Module | Rack::Cache::Options |
In: |
lib/rack/cache/options.rb
|
Configuration options and utility methods for option access. Rack::Cache uses the Rack Environment to store option values. All options documented below are stored in the Rack Environment as "rack-cache.<option>", where <option> is the option name.
# File lib/rack/cache/options.rb, line 11 11: def self.option_accessor(key) 12: name = option_name(key) 13: define_method(key) { || options[name] } 14: define_method("#{key}=") { |value| options[name] = value } 15: define_method("#{key}?") { || !! options[name] } 16: end
# File lib/rack/cache/options.rb, line 18 18: def option_name(key) 19: case key 20: when Symbol ; "rack-cache.#{key}" 21: when String ; key 22: else raise ArgumentError 23: end 24: end
The underlying options Hash. During initialization (or outside of a request), this is a default values Hash. During a request, this is the Rack environment Hash. The default values Hash is merged in underneath the Rack environment before each request is processed.
# File lib/rack/cache/options.rb, line 102 102: def options 103: @env || @default_options 104: end
Set an option. When option is a Symbol, it is set in the Rack Environment as "rack-cache.option". When option is a String, it exactly as specified. The option argument may also be a Hash in which case each key/value pair is merged into the environment as if the set method were called on each.
# File lib/rack/cache/options.rb, line 116 116: def set(option, value=self, &block) 117: if block_given? 118: write_option option, block 119: elsif value == self 120: self.options = option.to_hash 121: else 122: write_option option, value 123: end 124: end