Class: Card::Cache::Temporary
Instance Attribute Summary collapse
-
#store ⇒ Object
readonly
Returns the value of attribute store.
Instance Method Summary collapse
- #delete(key) ⇒ Object
- #dump ⇒ Object
- #exist?(key) ⇒ Boolean
- #fetch(key, &_block) ⇒ Object
-
#initialize ⇒ Temporary
constructor
A new instance of Temporary.
- #read(key) ⇒ Object
- #reset ⇒ Object
- #write(key, value) ⇒ Object
Constructor Details
#initialize ⇒ Temporary
Returns a new instance of Temporary.
4 5 6 |
# File 'lib/card/cache/temporary.rb', line 4 def initialize @store = {} end |
Instance Attribute Details
#store ⇒ Object (readonly)
Returns the value of attribute store.
2 3 4 |
# File 'lib/card/cache/temporary.rb', line 2 def store @store end |
Instance Method Details
#delete(key) ⇒ Object
21 22 23 |
# File 'lib/card/cache/temporary.rb', line 21 def delete key @store.delete key end |
#dump ⇒ Object
25 26 27 28 29 |
# File 'lib/card/cache/temporary.rb', line 25 def dump @store.each do |k, v| p "#{k} --> #{v.inspect[0..30]}" end end |
#exist?(key) ⇒ Boolean
35 36 37 |
# File 'lib/card/cache/temporary.rb', line 35 def exist? key @store.key? key end |
#fetch(key, &_block) ⇒ Object
17 18 19 |
# File 'lib/card/cache/temporary.rb', line 17 def fetch key, &_block read(key) || write(key, yield) end |
#read(key) ⇒ Object
8 9 10 11 |
# File 'lib/card/cache/temporary.rb', line 8 def read key return unless @store.key? key @store[key] end |
#reset ⇒ Object
31 32 33 |
# File 'lib/card/cache/temporary.rb', line 31 def reset @store = {} end |
#write(key, value) ⇒ Object
13 14 15 |
# File 'lib/card/cache/temporary.rb', line 13 def write key, value @store[key] = value end |