Class: Hoodie::Stash::MemStore
Overview
Basic cache object stash store (uses a Hash)
Instance Attribute Summary collapse
-
#:store(: store) ⇒ Stash::MemStash
readonly
Location of Stash::DiskStore store.
-
#store ⇒ Object
readonly
Returns the value of attribute 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) ⇒ Boolean
(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) ⇒ Boolean
return a boolean indicating presence of the given value in the store.
Constructor Details
#initialize(_ = {}) ⇒ Object
Initializes a new store object.
36 37 38 |
# File 'lib/hoodie/stash/mem_store.rb', line 36 def initialize(_ = {}) @store = {} end |
Instance Attribute Details
#:store(: store) ⇒ Stash::MemStash (readonly)
Returns location of Stash::DiskStore store.
28 |
# File 'lib/hoodie/stash/mem_store.rb', line 28 attr_reader :store |
#store ⇒ Object (readonly)
Returns the value of attribute store.
28 29 30 |
# File 'lib/hoodie/stash/mem_store.rb', line 28 def store @store end |
Instance Method Details
#[](key) ⇒ Hash, ...
Retrieves the value for a given key, if nothing is set, returns KeyError
60 61 62 |
# File 'lib/hoodie/stash/mem_store.rb', line 60 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.
90 91 92 |
# File 'lib/hoodie/stash/mem_store.rb', line 90 def []=(key, value) @store[key] = value end |
#clear!(key = nil) ⇒ Object
Clear the whole stash store or the value of a key
clear.
47 48 49 |
# File 'lib/hoodie/stash/mem_store.rb', line 47 def clear!(key = nil) key.nil? ? @store.clear : @store.delete(key) end |
#each { ... } ⇒ Object
Iterates over all key-value pairs.
100 101 102 |
# File 'lib/hoodie/stash/mem_store.rb', line 100 def each(&_block) @store.each { |k, v| yield(k, v) } end |
#include?(key) ⇒ Boolean Also known as: key?
return a boolean indicating presence of the given key in the store
130 131 132 |
# File 'lib/hoodie/stash/mem_store.rb', line 130 def include?(key) @store.include? key end |
#keys ⇒ Array<String, Symbol>
return all keys in the store as an array
149 150 151 |
# File 'lib/hoodie/stash/mem_store.rb', line 149 def keys @store.keys end |
#load(data) ⇒ Object
Loads a hash of data into the stash.
110 111 112 113 114 |
# File 'lib/hoodie/stash/mem_store.rb', line 110 def load(data) data.each do |key, value| @store[key] = value end end |
#size ⇒ Fixnum
return the size of the store as an integer
120 121 122 |
# File 'lib/hoodie/stash/mem_store.rb', line 120 def size @store.size end |
#value?(value) ⇒ Boolean
return a boolean indicating presence of the given value in the store
141 142 143 |
# File 'lib/hoodie/stash/mem_store.rb', line 141 def value?(value) @store.value? value end |