Skip to content
Browse files

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
  • Loading branch information...
1 parent 85741dd commit cff0e51ae946a2edc0216fb29c1496109c247d68 @carlosantoniodasilva carlosantoniodasilva committed Dec 13, 2012
View
2 actionpack/lib/abstract_controller/helpers.rb
@@ -19,7 +19,7 @@ module ClassMethods
def inherited(klass)
helpers = _helpers
klass._helpers = Module.new { include helpers }
- klass.class_eval { default_helper_module! unless anonymous? }
+ klass.class_eval { default_helper_module! } unless klass.anonymous?
super
end
View
9 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 @@ def modules_for_helpers(args)
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
View
3 actionpack/lib/action_controller/metal/redirecting.rb
@@ -94,8 +94,7 @@ def _compute_redirect_to_location(options)
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

0 comments on commit cff0e51

Please sign in to comment.
Something went wrong with that request. Please try again.