From cff0e51ae946a2edc0216fb29c1496109c247d68 Mon Sep 17 00:00:00 2001 From: Carlos Antonio da Silva Date: Thu, 13 Dec 2012 08:46:12 -0200 Subject: 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 --- actionpack/lib/action_controller/metal/helpers.rb | 9 ++++----- actionpack/lib/action_controller/metal/redirecting.rb | 3 +-- 2 files changed, 5 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_controller/metal') 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 -- cgit v1.2.3