aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller/filters.rb
diff options
context:
space:
mode:
authorrick <technoweenie@gmail.com>2008-07-16 14:20:15 -0700
committerrick <technoweenie@gmail.com>2008-07-16 14:20:15 -0700
commit0a6d75dedd79407376aae1f01302164dfd3e44b6 (patch)
treedfef7e73b3b19a65895651c82cb6e0b727394eab /actionpack/lib/action_controller/filters.rb
parenta14cedc7797aef4ccd9da46ed73e36d730392814 (diff)
parentfc89a951933638b051bb1f9e1339ee6ae7c94cda (diff)
downloadrails-0a6d75dedd79407376aae1f01302164dfd3e44b6.tar.gz
rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.tar.bz2
rails-0a6d75dedd79407376aae1f01302164dfd3e44b6.zip
merge with local tweaks
Diffstat (limited to 'actionpack/lib/action_controller/filters.rb')
-rw-r--r--actionpack/lib/action_controller/filters.rb31
1 files changed, 28 insertions, 3 deletions
diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb
index 155d8b480a..10dc0cc45b 100644
--- a/actionpack/lib/action_controller/filters.rb
+++ b/actionpack/lib/action_controller/filters.rb
@@ -94,7 +94,7 @@ module ActionController #:nodoc:
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 @@ module ActionController #:nodoc:
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 @@ module ActionController #:nodoc:
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 @@ module ActionController #:nodoc:
def included_in_action?(controller, options)
if options[:only]
- Array(options[:only]).map(&:to_s).include?(controller.action_name)
+ options[:only].include?(controller.action_name)
elsif options[:except]
- !Array(options[:except]).map(&:to_s).include?(controller.action_name)
+ !options[:except].include?(controller.action_name)
else
true
end
@@ -138,6 +155,14 @@ module ActionController #:nodoc:
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: