From ceb0790321c8037cbe03a8ea3b09c7be9494c484 Mon Sep 17 00:00:00 2001 From: Daniel Neighman Date: Mon, 23 Jun 2008 03:08:00 +1000 Subject: [PATCH] Makes sure that the action cache is getting setup on the controller with cache_actions --- lib/merb-cache/controller.rb | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/merb-cache/controller.rb b/lib/merb-cache/controller.rb index 827bdcf..9697297 100644 --- a/lib/merb-cache/controller.rb +++ b/lib/merb-cache/controller.rb @@ -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) @@ -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 @@ -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 @@ -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