Class: Money::RatesStore::StoreWithHistoricalDataSupport
- Inherits:
-
Memory
- Object
- Memory
- Money::RatesStore::StoreWithHistoricalDataSupport
- Defined in:
- lib/money/rates_store/store_with_historical_data_support.rb
Constant Summary collapse
- INDEX_DATE_SEPARATOR =
'_AT_'.freeze
Instance Method Summary collapse
- #add_rate(currency_iso_from, currency_iso_to, rate, date = nil) ⇒ Object
-
#each_rate {|iso_from, iso_to, rate, date| ... } ⇒ Enumerator
Iterate over rate tuples (iso_from, iso_to, rate).
- #get_rate(currency_iso_from, currency_iso_to, date = nil) ⇒ Object
-
#transaction(_force_sync = false, &block) ⇒ Object
Wraps block execution in a thread-safe transaction.
Instance Method Details
#add_rate(currency_iso_from, currency_iso_to, rate, date = nil) ⇒ Object
5 6 7 |
# File 'lib/money/rates_store/store_with_historical_data_support.rb', line 5 def add_rate(currency_iso_from, currency_iso_to, rate, date = nil) transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] = rate } end |
#each_rate {|iso_from, iso_to, rate, date| ... } ⇒ Enumerator
Iterate over rate tuples (iso_from, iso_to, rate)
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/money/rates_store/store_with_historical_data_support.rb', line 31 def each_rate(&block) enum = Enumerator.new do |yielder| rates.each do |key, rate| iso_from, iso_to = key.split(Memory::INDEX_KEY_SEPARATOR) iso_to, date = iso_to.split(INDEX_DATE_SEPARATOR) date = Date.parse(date) if date yielder.yield iso_from, iso_to, rate, date end end block_given? ? enum.each(&block) : enum end |
#get_rate(currency_iso_from, currency_iso_to, date = nil) ⇒ Object
9 10 11 |
# File 'lib/money/rates_store/store_with_historical_data_support.rb', line 9 def get_rate(currency_iso_from, currency_iso_to, date = nil) transaction { rates[rate_key_for(currency_iso_from, currency_iso_to, date)] } end |
#transaction(_force_sync = false, &block) ⇒ Object
Wraps block execution in a thread-safe transaction
14 15 16 |
# File 'lib/money/rates_store/store_with_historical_data_support.rb', line 14 def transaction(_force_sync = false, &block) super(&block) end |