diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-13 08:46:12 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2012-12-13 08:46:12 -0200 |
commit | cff0e51ae946a2edc0216fb29c1496109c247d68 (patch) | |
tree | 1965313d84b6a5113a017f640620ee4ca002f0b3 /actionpack/lib/action_controller/metal | |
parent | 85741dd1750fe5cb68e04b876ea61f6065982ac2 (diff) | |
download | rails-cff0e51ae946a2edc0216fb29c1496109c247d68.tar.gz rails-cff0e51ae946a2edc0216fb29c1496109c247d68.tar.bz2 rails-cff0e51ae946a2edc0216fb29c1496109c247d68.zip |
Refactor helpers code in Action Pack a bit
* Avoid calling class_eval when not needed
* Remove helpers_path attr accessor, it's defined as a class attribute a
few lines later
* Avoid creating extra arrays when finding helpers, use flat_map and sort!
* Remove not required refer variable when redirecting :back
Diffstat (limited to 'actionpack/lib/action_controller/metal')
-rw-r--r-- | actionpack/lib/action_controller/metal/helpers.rb | 9 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/redirecting.rb | 3 |
2 files changed, 5 insertions, 7 deletions
diff --git a/actionpack/lib/action_controller/metal/helpers.rb b/actionpack/lib/action_controller/metal/helpers.rb index d2cbbd3330..6b1bc88e2b 100644 --- a/actionpack/lib/action_controller/metal/helpers.rb +++ b/actionpack/lib/action_controller/metal/helpers.rb @@ -50,7 +50,6 @@ module ActionController module Helpers extend ActiveSupport::Concern - class << self; attr_accessor :helpers_path; end include AbstractController::Helpers included do @@ -91,11 +90,11 @@ module ActionController end def all_helpers_from_path(path) - helpers = [] - Array(path).each do |_path| - extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/ + helpers = Array(path).flat_map do |_path| + extract = /^#{Regexp.quote(_path.to_s)}\/?(.*)_helper.rb$/ names = Dir["#{_path}/**/*_helper.rb"].map { |file| file.sub(extract, '\1') } - helpers += names.sort + names.sort! + names end helpers.uniq! helpers diff --git a/actionpack/lib/action_controller/metal/redirecting.rb b/actionpack/lib/action_controller/metal/redirecting.rb index 4250ea9f71..091facfd8d 100644 --- a/actionpack/lib/action_controller/metal/redirecting.rb +++ b/actionpack/lib/action_controller/metal/redirecting.rb @@ -94,8 +94,7 @@ module ActionController when String request.protocol + request.host_with_port + options when :back - raise RedirectBackError unless refer = request.headers["Referer"] - refer + request.headers["Referer"] or raise RedirectBackError when Proc _compute_redirect_to_location options.call else |