class Money::Currency::RateStore::Memory

Overview

Class for concurrency-safe storage of exchange rate pairs. Used by instances of Currency::VariableExchange.

store = Money::Currency::RateStore::Memory.new
store["USD", "CAD"] = 0.98
store["USD", "CAD"] # => 0.98

# Iterates rates
store.each do |rate|
  puts rate
end

Defined in:

money/currency/rate_store/memory.cr

Constant Summary

INDEX_KEY_SEPARATOR = '_'

Constructors

Instance Method Summary

Instance methods inherited from class Money::Currency::RateStore

[](from, to) : BigDecimal [], []=(from, to, value : Number) : Nil []=, []?(from, to) : BigDecimal | Nil []?, add_rate(from : Currency, to : Currency, value : Int64) : Nil add_rate, clear : Nil clear, clear_rates : Nil clear_rates, each(&block : T -> _) each, get_rate?(from : Currency, to : Currency) : Rate | Nil get_rate?, transaction(&block : -> _) transaction

Constructor Detail

def self.new #

Initializes a new RateStore::Memory object.


[View source]

Instance Method Detail

def each(&) #
Description copied from class Money::Currency::RateStore

Iterates over list of Rate objects.

store.each do |rate|
  puts rate
end

[View source]
def transaction(& : -> _) #

Wraps block execution in a thread-safe transaction.

NOTE Uses Mutex to synchronize data access.


[View source]