Module: Rack::Client::Cache::Options
Overview
vendored, originally from rack-cache.
Class Method Summary collapse
Instance Method Summary collapse
-
#options ⇒ Object
The underlying options Hash.
-
#options=(hash = {}) ⇒ Object
Set multiple options.
-
#set(option, value = self, &block) ⇒ Object
Set an option.
Class Method Details
.option_accessor(key) ⇒ Object
6 7 8 9 10 11 |
# File 'lib/rack/client/middleware/cache/options.rb', line 6 def self.option_accessor(key) name = option_name(key) define_method(key) { || [name] } define_method("#{key}=") { |value| [name] = value } define_method("#{key}?") { || !! [name] } end |
.option_name(key) ⇒ Object
13 14 15 16 17 18 19 |
# File 'lib/rack/client/middleware/cache/options.rb', line 13 def option_name(key) case key when Symbol ; "rack-client-cache.#{key}" when String ; key else raise ArgumentError end end |
Instance Method Details
#options ⇒ Object
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.
97 98 99 |
# File 'lib/rack/client/middleware/cache/options.rb', line 97 def @env || @default_options end |
#options=(hash = {}) ⇒ Object
Set multiple options.
102 103 104 |
# File 'lib/rack/client/middleware/cache/options.rb', line 102 def (hash={}) hash.each { |key,value| write_option(key, value) } end |
#set(option, value = self, &block) ⇒ Object
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.
111 112 113 114 115 116 117 118 119 |
# File 'lib/rack/client/middleware/cache/options.rb', line 111 def set(option, value=self, &block) if block_given? write_option option, block elsif value == self self. = option.to_hash else write_option option, value end end |