Class: Garner::Cache::Identity
- Inherits:
-
Object
- Object
- Garner::Cache::Identity
- Defined in:
- lib/garner/cache/identity.rb
Instance Attribute Summary collapse
-
#bindings ⇒ Object
Returns the value of attribute bindings.
-
#key_hash ⇒ Object
Returns the value of attribute key_hash.
-
#options_hash ⇒ Object
Returns the value of attribute options_hash.
Instance Method Summary collapse
-
#bind(object, &block) ⇒ Object
Bind this cache identity to a (bindable) object.
- #fetch(&block) ⇒ Object
-
#initialize ⇒ Identity
constructor
A new instance of Identity.
-
#key(hash, &block) ⇒ Object
Merge the given hash into the cache identity’s key hash.
-
#options(hash, &block) ⇒ Object
Merge the given hash into the cache identity’s cache options.
Constructor Details
#initialize ⇒ Identity
Returns a new instance of Identity.
6 7 8 9 10 11 12 13 |
# File 'lib/garner/cache/identity.rb', line 6 def initialize @bindings = [] @key_hash = {} # Set up options hash with defaults @options_hash = Garner.config. || {} @options_hash.merge!({ :expires_in => Garner.config.expires_in }) end |
Instance Attribute Details
#bindings ⇒ Object
Returns the value of attribute bindings.
4 5 6 |
# File 'lib/garner/cache/identity.rb', line 4 def bindings @bindings end |
#key_hash ⇒ Object
Returns the value of attribute key_hash.
4 5 6 |
# File 'lib/garner/cache/identity.rb', line 4 def key_hash @key_hash end |
#options_hash ⇒ Object
Returns the value of attribute options_hash.
4 5 6 |
# File 'lib/garner/cache/identity.rb', line 4 def @options_hash end |
Instance Method Details
#bind(object, &block) ⇒ Object
Bind this cache identity to a (bindable) object.
22 23 24 25 |
# File 'lib/garner/cache/identity.rb', line 22 def bind(object, &block) @bindings << object block_given? ? fetch(&block) : self end |
#fetch(&block) ⇒ Object
15 16 17 |
# File 'lib/garner/cache/identity.rb', line 15 def fetch(&block) Garner::Cache.fetch(@bindings, @key_hash, @options_hash, &block) end |
#key(hash, &block) ⇒ Object
Merge the given hash into the cache identity’s key hash.
30 31 32 33 |
# File 'lib/garner/cache/identity.rb', line 30 def key(hash, &block) @key_hash.merge!(hash) block_given? ? fetch(&block) : self end |
#options(hash, &block) ⇒ Object
Merge the given hash into the cache identity’s cache options. Any cache_options supported by Garner.config.cache may be passed.
39 40 41 42 |
# File 'lib/garner/cache/identity.rb', line 39 def (hash, &block) @options_hash.merge!(hash) block_given? ? fetch(&block) : self end |