Class: ExchangeRateJt::DataStore::PStoreAdaptor
- Inherits:
-
Object
- Object
- ExchangeRateJt::DataStore::PStoreAdaptor
- Defined in:
- lib/exchange_rate_jt/data_store/p_store_adaptor.rb
Instance Attribute Summary collapse
-
#data_store ⇒ Object
readonly
Returns the value of attribute data_store.
Instance Method Summary collapse
- #fetch(key, value) ⇒ Object
-
#initialize(data_store) ⇒ PStoreAdaptor
constructor
A new instance of PStoreAdaptor.
- #persist(key, value) ⇒ Object
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_store ⇒ Object (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
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 |