aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJamis Buck <jamis@37signals.com>2006-10-21 16:55:14 +0000
committerJamis Buck <jamis@37signals.com>2006-10-21 16:55:14 +0000
commitda18193d5ff0647bf7e459eee21ee5762de83d1b (patch)
treece6b653ca24b3890335722838bf6feac8c6ad51f /actionpack
parent8949ce09824b8a6796c3257fd6ebb01d9014fe9c (diff)
downloadrails-da18193d5ff0647bf7e459eee21ee5762de83d1b.tar.gz
rails-da18193d5ff0647bf7e459eee21ee5762de83d1b.tar.bz2
rails-da18193d5ff0647bf7e459eee21ee5762de83d1b.zip
More consistent implementation of filter replacement (thanks Martin! closes #5949)
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5331 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/filters.rb64
1 files changed, 22 insertions, 42 deletions
diff --git a/actionpack/lib/action_controller/filters.rb b/actionpack/lib/action_controller/filters.rb
index 83275bb5a6..113dba05d2 100644
--- a/actionpack/lib/action_controller/filters.rb
+++ b/actionpack/lib/action_controller/filters.rb
@@ -248,10 +248,7 @@ module ActionController #:nodoc:
# The passed <tt>filters</tt> will be appended to the filter_chain and
# will execute before the action on this controller is performed.
def append_before_filter(*filters, &block)
- new_filters, existing_filters = look_for_existing_filters(filters, :before)
-
- append_filter_to_chain(new_filters, :before, &block)
- skip_before_filter(existing_filters) unless existing_filters.empty?
+ append_filter_to_chain(filters, :before, &block)
end
# The passed <tt>filters</tt> will be prepended to the filter_chain and
@@ -266,10 +263,7 @@ module ActionController #:nodoc:
# The passed <tt>filters</tt> will be appended to the array of filters
# that run _after_ actions on this controller are performed.
def append_after_filter(*filters, &block)
- new_filters, existing_filters = look_for_existing_filters(filters, :after)
-
- prepend_filter_to_chain(new_filters, :after, &block)
- skip_after_filter(existing_filters) unless existing_filters.empty?
+ prepend_filter_to_chain(filters, :after, &block)
end
# The passed <tt>filters</tt> will be prepended to the array of filters
@@ -411,6 +405,10 @@ module ActionController #:nodoc:
false
end
+ def around?
+ true
+ end
+
def call(controller, &block)
raise(ActionControllerError, 'No filter type: Nothing to do here.')
end
@@ -422,6 +420,10 @@ module ActionController #:nodoc:
def filter
@filter.filter
end
+
+ def around?
+ false
+ end
end
class BeforeFilterProxy < FilterProxy #:nodoc:
@@ -494,27 +496,26 @@ module ActionController #:nodoc:
def create_filters(filters, position, &block) #:nodoc:
filters, conditions = extract_conditions(filters, &block)
+ filters.map! { |filter| find_or_create_filter(filter,position) }
+ update_conditions(filters, conditions)
+ filters
+ end
- filters.map! do |filter|
- # change all the filters into instances of Filter derived classes
- class_for_filter(filter).new(filter)
- end
-
- filters.map! do |filter|
+ def find_or_create_filter(filter,position)
+ if found_filter = find_filter(filter) { |f| f.send("#{position}?") }
+ found_filter
+ else
+ f = class_for_filter(filter).new(filter)
# apply proxy to filter if necessary
case position
when :before
- BeforeFilterProxy.new(filter)
+ BeforeFilterProxy.new(f)
when :after
- AfterFilterProxy.new(filter)
+ AfterFilterProxy.new(f)
else
- filter
+ f
end
end
-
- update_conditions(filters, conditions)
-
- filters
end
# The determination of the filter type was once done at run time.
@@ -603,27 +604,6 @@ module ActionController #:nodoc:
end
end
end
-
- def look_for_existing_filters(filters, which)
- filters, options = extract_conditions(filters)
- old_filters = []
-
- filter_chain.select(&"#{which}?".to_sym).each do |f|
- old_filters << f.filter if filters.include?(f.filter)
- end
-
- new_filters = filters - old_filters + [options]
-
- if options[:except]
- old_filters << { :only => options[:except] }
- elsif options[:only]
- old_filters << { :except => options[:only] }
- else
- old_filters = []
- end
-
- [new_filters, old_filters]
- end
end
module InstanceMethods # :nodoc: