Class: MemStash::Cache
- Includes:
- Enumerable
- Defined in:
- lib/hoodie/stash/mem_store.rb
Overview
Basic cache object stash store (uses a Hash)
Instance Attribute Summary collapse
-
#store ⇒ Hash
readonly
Of the mem stash cache hash store.
Instance Method Summary collapse
-
#[](key) ⇒ Hash, ...
Retrieves the value for a given key, if nothing is set, returns KeyError.
-
#[]=(key, value) ⇒ Object
Store the given value with the given key, either an an argument or block.
-
#clear!(key = nil) ⇒ Object
Clear the whole stash store or the value of a key.
-
#each(&block) { ... } ⇒ Object
Iterates over all key-value pairs.
-
#include?(key) ⇒ TrueClass, FalseClass
(also: #key?)
return a boolean indicating presence of the given key in the store.
-
#initialize(_ = {}) ⇒ Object
constructor
Initializes a new store object.
-
#keys ⇒ Array<String, Symbol>
return all keys in the store as an array.
-
#load(data) ⇒ Object
Loads a hash of data into the stash.
-
#size ⇒ Fixnum
return the size of the store as an integer.
-
#value?(value) ⇒ TrueClass, FalseClass
return a boolean indicating presence of the given value in the store.
Constructor Details
#initialize(_ = {}) ⇒ Object
Initializes a new store object.
35 36 37 |
# File 'lib/hoodie/stash/mem_store.rb', line 35 def initialize(_ = {}) @store = {} end |
Instance Attribute Details
#store ⇒ Hash (readonly)
Returns of the mem stash cache hash store.
27 28 29 |
# File 'lib/hoodie/stash/mem_store.rb', line 27 def store @store end |
Instance Method Details
#[](key) ⇒ Hash, ...
Retrieves the value for a given key, if nothing is set, returns KeyError
59 60 61 |
# File 'lib/hoodie/stash/mem_store.rb', line 59 def [](key) @store[key] end |
#[]=(key, value) ⇒ Object
Store the given value with the given key, either an an argument or block. If a previous value was set it will be overwritten with the new value.
87 88 89 |
# File 'lib/hoodie/stash/mem_store.rb', line 87 def []=(key, value) @store[key] = value end |
#clear!(key = nil) ⇒ Object
Clear the whole stash store or the value of a key
clear.
46 47 48 |
# File 'lib/hoodie/stash/mem_store.rb', line 46 def clear!(key = nil) key.nil? ? @store.clear : @store.delete(key) end |
#each(&block) { ... } ⇒ Object
Iterates over all key-value pairs.
97 98 99 |
# File 'lib/hoodie/stash/mem_store.rb', line 97 def each(&block) @store.each { |k, v| yield(k, v) } end |
#include?(key) ⇒ TrueClass, FalseClass Also known as: key?
return a boolean indicating presence of the given key in the store
127 128 129 |
# File 'lib/hoodie/stash/mem_store.rb', line 127 def include?(key) @store.include? key end |
#keys ⇒ Array<String, Symbol>
return all keys in the store as an array
146 147 148 |
# File 'lib/hoodie/stash/mem_store.rb', line 146 def keys @store.keys end |
#load(data) ⇒ Object
Loads a hash of data into the stash.
107 108 109 110 111 |
# File 'lib/hoodie/stash/mem_store.rb', line 107 def load(data) data.each do |key, value| @store[key] = value end end |
#size ⇒ Fixnum
return the size of the store as an integer
117 118 119 |
# File 'lib/hoodie/stash/mem_store.rb', line 117 def size @store.size end |
#value?(value) ⇒ TrueClass, FalseClass
return a boolean indicating presence of the given value in the store
138 139 140 |
# File 'lib/hoodie/stash/mem_store.rb', line 138 def value?(value) @store.value? value end |