Class: ExchangeRateJt::DataStore::PStoreAdaptor

Inherits:
Object
  • Object
show all
Defined in:
lib/exchange_rate_jt/data_store/p_store_adaptor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data_store) ⇒ PStoreAdaptor

Returns a new instance of PStoreAdaptor.



11
12
13
14
15
16
# File 'lib/exchange_rate_jt/data_store/p_store_adaptor.rb', line 11

def initialize(data_store)
  unless data_store.is_a?(PStore)
    raise InvalidConnectionTypeError, 'Invalid connection type'
  end
  @data_store = data_store
end

Instance Attribute Details

#data_storeObject (readonly)

Returns the value of attribute data_store.



9
10
11
# File 'lib/exchange_rate_jt/data_store/p_store_adaptor.rb', line 9

def data_store
  @data_store
end

Instance Method Details

#fetch(key, value) ⇒ Object

Raises:



25
26
27
28
29
# File 'lib/exchange_rate_jt/data_store/p_store_adaptor.rb', line 25

def fetch(key, value)
  data = data_store.transaction { data_store[key][value] }
  raise DataNotFoundError, 'Data not found' if data.nil?
  data
end

#persist(key, value) ⇒ Object



18
19
20
21
22
23
# File 'lib/exchange_rate_jt/data_store/p_store_adaptor.rb', line 18

def persist(key, value)
  data_store.transaction do
    data_store[key] = value
    data_store.commit
  end
end