Class: Jouba::MemoryStore

Inherits:
Object
  • Object
show all
Defined in:
lib/jouba/store.rb

Direct Known Subclasses

EventStore

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeMemoryStore

Returns a new instance of MemoryStore.



8
9
10
# File 'lib/jouba/store.rb', line 8

def initialize
  flush
end

Instance Attribute Details

#dbObject (readonly)

Returns the value of attribute db.



6
7
8
# File 'lib/jouba/store.rb', line 6

def db
  @db
end

Class Method Details

.load(file_path) ⇒ Object



32
33
34
# File 'lib/jouba/store.rb', line 32

def self.load(file_path)
  new.tap { |store| store.instance_variable_set('@db', YAML.load_file(file_path)) }
end

Instance Method Details

#delete(key) ⇒ Object



20
21
22
# File 'lib/jouba/store.rb', line 20

def delete(key)
  db.delete(key)
end

#flushObject



24
25
26
# File 'lib/jouba/store.rb', line 24

def flush
  @db = {}
end

#get(key, _ = {}) ⇒ Object



12
13
14
# File 'lib/jouba/store.rb', line 12

def get(key, _ = {})
  db[key].nil? ? nil : deserialize(db[key])
end

#persist(file_path) ⇒ Object



28
29
30
# File 'lib/jouba/store.rb', line 28

def persist(file_path)
  File.open(file_path, 'w') { |file| file.write @db.to_yaml }
end

#set(key, value) ⇒ Object



16
17
18
# File 'lib/jouba/store.rb', line 16

def set(key, value)
  db[key] = serialize(value)
end