Skip to content

Commit

Permalink
Refactor Filter predicate methods to use inheritance. [#815 state:res…
Browse files Browse the repository at this point in the history
…olved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
joshsusser authored and lifo committed Aug 13, 2008
1 parent 1ee9e3f commit 2561be0
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions actionpack/lib/action_controller/filters.rb
Expand Up @@ -109,16 +109,17 @@ def initialize(kind, method, options = {})
update_options! options
end

# override these to return true in appropriate subclass
def before?
self.class == BeforeFilter
false
end

def after?
self.class == AfterFilter
false
end

def around?
self.class == AroundFilter
false
end

# Make sets of strings from :only/:except options
Expand Down Expand Up @@ -170,6 +171,10 @@ def type
:around
end

def around?
true
end

def call(controller, &block)
if should_run_callback?(controller)
method = filter_responds_to_before_and_after? ? around_proc : self.method
Expand Down Expand Up @@ -212,6 +217,10 @@ def type
:before
end

def before?
true
end

def call(controller, &block)
super
if controller.send!(:performed?)
Expand All @@ -224,6 +233,10 @@ class AfterFilter < Filter #:nodoc:
def type
:after
end

def after?
true
end
end

# Filters enable controllers to run shared pre- and post-processing code for its actions. These filters can be used to do
Expand Down

0 comments on commit 2561be0

Please sign in to comment.