class
Money::Currency::RateStore::File
- Money::Currency::RateStore::File
- Money::Currency::RateStore::Memory
- Money::Currency::RateStore
- Reference
- Object
Overview
Class for storage of exchange rate pairs in a JSON file.
NOTE Exchange rates are stored in memory and are automatically loaded from (upon initialization), and persisted to a JSON file (on every mutable transaction commit).
store = Money::Currency::RateStore::File.new("path/to/file.json")
store["USD", "CAD"] = 0.98
store["USD", "CAD"] # => 0.98
# Iterates rates
store.each do |rate|
puts rate
end
# Save rates
store.save
Defined in:
money/currency/rate_store/file.crConstructors
Instance Method Summary
-
#load : Nil
Loads rates from a JSON file.
-
#save : Nil
Saves rates to a JSON file.
-
#transaction(*, mutable : Bool = false, & : -> _)
Wraps block execution in a concurrency-safe transaction.
Instance methods inherited from class Money::Currency::RateStore
<<(rate : Rate) : self<<(rates : Enumerable(Rate)) : self <<, [](from : String | Symbol | Currency, to : String | Symbol | Currency) : BigDecimal [], []=(from : String | Symbol | Currency, to : String | Symbol | Currency, value : Number) : Nil []=, []?(from : String | Symbol | Currency, to : String | Symbol | Currency) : BigDecimal | Nil []?, clear(base_currency : String | Symbol | Currency) : Nil
clear : Nil clear, each(& : Rate -> _) : Nil each, rates : Array(Rate) rates, transaction(*, mutable : Bool = false, & : -> _) transaction
Constructor methods inherited from class Money::Currency::RateStore
new(ttl : Time::Span | Nil = nil)
new
Constructor Detail
Instance Method Detail
def transaction(*, mutable : Bool = false, & : -> _)
#
Wraps block execution in a concurrency-safe transaction.