Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Don't repeatedly convert only/except options

  • Loading branch information...
commit 0ce7fe5308337ae0b0394ae4c18b59cf64e33b38 1 parent ce4a1bb
@jeremy jeremy authored
Showing with 28 additions and 3 deletions.
  1. +28 −3 actionpack/lib/action_controller/filters.rb
View
31 actionpack/lib/action_controller/filters.rb
@@ -94,7 +94,7 @@ def update_filter_in_chain(filters, options, &test)
map! do |filter|
if filters.include?(filter)
new_filter = filter.dup
- new_filter.options.merge!(options)
+ new_filter.update_options!(options)
new_filter
else
filter
@@ -104,6 +104,11 @@ def update_filter_in_chain(filters, options, &test)
end
class Filter < ActiveSupport::Callbacks::Callback #:nodoc:
+ def initialize(kind, method, options = {})
+ super
+ update_options! options
+ end
+
def before?
self.class == BeforeFilter
end
@@ -116,6 +121,18 @@ def around?
self.class == AroundFilter
end
+ # Make sets of strings from :only/:except options
+ def update_options!(other)
+ if other
+ convert_only_and_except_options_to_sets_of_strings(other)
+ if other[:skip]
+ convert_only_and_except_options_to_sets_of_strings(other[:skip])
+ end
+ end
+
+ options.update(other)
+ end
+
private
def should_not_skip?(controller)
if options[:skip]
@@ -127,9 +144,9 @@ def should_not_skip?(controller)
def included_in_action?(controller, options)
if options[:only]
- Array(options[:only]).map { |o| o.to_s }.include?(controller.action_name)
+ options[:only].include?(controller.action_name)
elsif options[:except]
- !Array(options[:except]).map { |o| o.to_s }.include?(controller.action_name)
+ !options[:except].include?(controller.action_name)
else
true
end
@@ -138,6 +155,14 @@ def included_in_action?(controller, options)
def should_run_callback?(controller)
should_not_skip?(controller) && included_in_action?(controller, options) && super
end
+
+ def convert_only_and_except_options_to_sets_of_strings(opts)
+ [:only, :except].each do |key|
+ if values = opts[key]
+ opts[key] = Array(values).map(&:to_s).to_set
+ end
+ end
+ end
end
class AroundFilter < Filter #:nodoc:

0 comments on commit 0ce7fe5

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