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 { ... } ⇒ 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.
89 90 91 |
# File 'lib/hoodie/stash/mem_store.rb', line 89 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 { ... } ⇒ Object
Iterates over all key-value pairs.
99 100 101 |
# File 'lib/hoodie/stash/mem_store.rb', line 99 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
129 130 131 |
# File 'lib/hoodie/stash/mem_store.rb', line 129 def include?(key) @store.include? key end |
#keys ⇒ Array<String, Symbol>
return all keys in the store as an array
148 149 150 |
# File 'lib/hoodie/stash/mem_store.rb', line 148 def keys @store.keys end |
#load(data) ⇒ Object
Loads a hash of data into the stash.
109 110 111 112 113 |
# File 'lib/hoodie/stash/mem_store.rb', line 109 def load(data) data.each do |key, value| @store[key] = value end end |
#size ⇒ Fixnum
return the size of the store as an integer
119 120 121 |
# File 'lib/hoodie/stash/mem_store.rb', line 119 def size @store.size end |
#value?(value) ⇒ TrueClass, FalseClass
return a boolean indicating presence of the given value in the store
140 141 142 |
# File 'lib/hoodie/stash/mem_store.rb', line 140 def value?(value) @store.value? value end |