Skip to content

Commit

Permalink
Makes sure that the action cache is getting setup on the controller w…
Browse files Browse the repository at this point in the history
…ith cache_actions
  • Loading branch information
Daniel Neighman committed Jun 22, 2008
1 parent 036e206 commit ceb0790
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/merb-cache/controller.rb
Expand Up @@ -5,7 +5,7 @@ module ControllerClassMethods
def cache_action(action, options = {}, &block)
# Get the filter options
opts = {}
[:exclude, :only, :with].each{ |k| r = options.delete(k); opts.merge!(r) if r}
opts = normalize_filters!(opts || {})

# setup the options for the before_filter
opts.delete(:exclude)
Expand All @@ -20,6 +20,8 @@ def cache_action(action, options = {}, &block)
a = Proc.new do
_set_action_cache(options)
end

# Using procs so that we can run multiple filters on _fetch_action_cache and _set_action_cache
before nil, opts, &b
after nil, opts, &a
end
Expand All @@ -28,15 +30,19 @@ def cache_action(action, options = {}, &block)
def cache_actions(*args, &block)
options = args.pop if Hash === args.last
options ||= {}
opts = {}
[:exclude, :only, :with].each{ |k| r = options.delete(k); opts.merge!(r) if r}
opts = normalize_filters!(opts || {})

if args.empty?
unless opts[:exclude]
args = self.callable_actions
opts[:only] = args.flatten
end
case opts.keys
when include?(:exclude)
actions = self.callable_actions - opts[:exclude]
when include?(:only)
actions = opts[:only]
else
actions = args.empty? ? self.callable_actions : args.flatten
end

# Setup the cache store on the controller
actions.each{|a| _add_action_cache(action.to_sym, options, &block)}

# Setup a before filter and after filter
b = Proc.new do
Expand All @@ -45,6 +51,8 @@ def cache_actions(*args, &block)
a = Proc.new do
_set_action_cache(options)
end

# Using procs so that we can run multiple filters on _fetch_action_cache and _set_action_cache
before nil, opts, &b
after nil, opts, &a
end
Expand Down

0 comments on commit ceb0790

Please sign in to comment.