Class: ActionParamCaching::ActionConfig
- Inherits:
-
Object
- Object
- ActionParamCaching::ActionConfig
- Defined in:
- lib/action_param_caching/action_config.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#argz ⇒ Object
readonly
Returns the value of attribute argz.
-
#did_config_cache ⇒ Object
Returns the value of attribute did_config_cache.
-
#expires_in ⇒ Object
readonly
Returns the value of attribute expires_in.
-
#filter_starting_with ⇒ Object
readonly
Returns the value of attribute filter_starting_with.
-
#valid_params ⇒ Object
readonly
Returns the value of attribute valid_params.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_args ⇒ Object
- #filtered_path_proc ⇒ Object
- #if_proc ⇒ Object
-
#initialize(controller_path, action, valid_params = [], filter_starting_with = nil, expires_in = nil) ⇒ ActionConfig
constructor
A new instance of ActionConfig.
- #path_proc ⇒ Object
Constructor Details
#initialize(controller_path, action, valid_params = [], filter_starting_with = nil, expires_in = nil) ⇒ ActionConfig
Returns a new instance of ActionConfig.
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/action_param_caching/action_config.rb', line 16 def initialize(controller_path, action, valid_params = [], filter_starting_with = nil, expires_in = nil) @action = action if valid_params and !valid_params.empty? @valid_params = valid_params @valid_params << :controller << :action << :format end @filter_starting_with = filter_starting_with @filter_starting_with ||= '_' @did_config_cache = false @expires_in = expires_in ActionParamCaching::ActionConfig.store_lookup(controller_path, action, self) end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
3 4 5 |
# File 'lib/action_param_caching/action_config.rb', line 3 def action @action end |
#argz ⇒ Object (readonly)
Returns the value of attribute argz.
3 4 5 |
# File 'lib/action_param_caching/action_config.rb', line 3 def argz @argz end |
#did_config_cache ⇒ Object
Returns the value of attribute did_config_cache.
4 5 6 |
# File 'lib/action_param_caching/action_config.rb', line 4 def did_config_cache @did_config_cache end |
#expires_in ⇒ Object (readonly)
Returns the value of attribute expires_in.
3 4 5 |
# File 'lib/action_param_caching/action_config.rb', line 3 def expires_in @expires_in end |
#filter_starting_with ⇒ Object (readonly)
Returns the value of attribute filter_starting_with.
3 4 5 |
# File 'lib/action_param_caching/action_config.rb', line 3 def filter_starting_with @filter_starting_with end |
#valid_params ⇒ Object (readonly)
Returns the value of attribute valid_params.
3 4 5 |
# File 'lib/action_param_caching/action_config.rb', line 3 def valid_params @valid_params end |
Class Method Details
.lookup ⇒ Object
12 13 14 |
# File 'lib/action_param_caching/action_config.rb', line 12 def self.lookup @lookup end |
.store_lookup(controller, action, config) ⇒ Object
6 7 8 9 10 |
# File 'lib/action_param_caching/action_config.rb', line 6 def self.store_lookup(controller, action, config) @lookup = {} if @lookup.nil? @lookup[controller] = {} if @lookup[controller].nil? @lookup[controller][action] = config end |
Instance Method Details
#cache_args ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/action_param_caching/action_config.rb', line 30 def cache_args @argz = {} if @valid_params && @valid_params.any? @argz[:if] = self.if_proc end if @filter_starting_with @argz[:cache_path] = self.filtered_path_proc else @argz[:cache_path] = self.path_proc end if @expires_in @argz[:expires_in] = self.expires_in end @argz end |
#filtered_path_proc ⇒ Object
50 51 52 53 54 |
# File 'lib/action_param_caching/action_config.rb', line 50 def filtered_path_proc Proc.new { |request| request.params.delete_if { |k,v| k.to_s.start_with?( ActionParamCaching::ActionConfig.lookup[request.params[:controller]][request.params[:action].to_sym].filter_starting_with) }.to_query } end |
#if_proc ⇒ Object
60 61 62 63 64 |
# File 'lib/action_param_caching/action_config.rb', line 60 def if_proc Proc.new { |request| request.params.collect{|key, value| ActionParamCaching::ActionConfig.lookup[request.params[:controller]][request.params[:action].to_sym].valid_params.include?(key.to_sym) || key.to_s.start_with?(ActionParamCaching::ActionConfig.lookup[request.params[:controller]][request.params[:action].to_sym].filter_starting_with)}.all? } end |
#path_proc ⇒ Object
56 57 58 |
# File 'lib/action_param_caching/action_config.rb', line 56 def path_proc Proc.new { |request| request.params.to_query } end |