module Money::RatesStore::DataSupport
Constants
- INDEX_DATE_SEPARATOR
Public Instance Methods
add_rate(currency_iso_from, currency_iso_to, rate, date = nil)
click to toggle source
# File lib/rates_store/data_support.rb, line 6 def add_rate(currency_iso_from, currency_iso_to, rate, date = nil) transaction do index[rate_key_for(currency_iso_from, currency_iso_to, date)] = rate end end
each_rate(&block)
click to toggle source
# File lib/rates_store/data_support.rb, line 37 def each_rate(&block) enum = Enumerator.new do |yielder| index.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)
click to toggle source
# File lib/rates_store/data_support.rb, line 12 def get_rate(currency_iso_from, currency_iso_to, date = nil) transaction do index[rate_key_for(currency_iso_from, currency_iso_to, date)] end end
transaction(force_sync = false) { |self| ... }
click to toggle source
# File lib/rates_store/data_support.rb, line 18 def transaction(force_sync = false, &block) if @mutex.respond_to?(:owned?) force_sync = false if @mutex.locked? && @mutex.owned? else force_sync = false end if !force_sync && (@in_transaction || options[:without_mutex]) yield self else @mutex.synchronize do @in_transaction = true result = yield @in_transaction = false result end end end
Private Instance Methods
rate_key_for(currency_iso_from, currency_iso_to, date = nil)
click to toggle source
# File lib/rates_store/data_support.rb, line 52 def rate_key_for(currency_iso_from, currency_iso_to, date = nil) key = [currency_iso_from, currency_iso_to]. join(Memory::INDEX_KEY_SEPARATOR) key = [key, date.to_s].join(INDEX_DATE_SEPARATOR) if date key.upcase end