Class: Card::Cache::Temporary

Inherits:
Object
  • Object
show all
Defined in:
lib/card/cache/temporary.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTemporary

Returns a new instance of Temporary.



4
5
6
# File 'lib/card/cache/temporary.rb', line 4

def initialize
  @store = {}
end

Instance Attribute Details

#storeObject (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

#dumpObject



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

Returns:

  • (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

#resetObject



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