Class: Pgai::Store

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

Constant Summary collapse

STORE_PATH =
"~/.config/pgai/config.pstore"

Instance Method Summary collapse

Instance Method Details

#all(record_type) ⇒ Object



11
12
13
14
15
# File 'lib/pgai/store.rb', line 11

def all(record_type)
  store.transaction(true) do
    store[record_type]&.values || {}
  end
end

#delete(record_type, id) ⇒ Object



23
24
25
26
27
28
# File 'lib/pgai/store.rb', line 23

def delete(record_type, id)
  store.transaction do
    store[record_type] ||= {}
    store[record_type] = store[record_type].except(id)
  end
end

#find(record_type, id) ⇒ Object



17
18
19
20
21
# File 'lib/pgai/store.rb', line 17

def find(record_type, id)
  store.transaction(true) do
    (store[record_type] || {})[id]
  end
end

#save(record_type, attributes, key: :id) ⇒ Object



30
31
32
33
34
35
# File 'lib/pgai/store.rb', line 30

def save(record_type, attributes, key: :id)
  store.transaction do
    store[record_type] ||= {}
    store[record_type].merge!(attributes[key] => attributes)
  end
end