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
-
.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
Class for storage of exchange rate pairs in a JSON file.
-
.new(pull : JSON::PullParser)
Class for storage of exchange rate pairs in a JSON file.
- .new(path : Path | String, *, ttl : Time::Span | Nil = nil)
Class Method Summary
-
.key : String
Returns the class key.
Instance Method Summary
-
#load : Nil
Loads rates from a JSON file.
- #path : Path
- #path=(path : Path)
-
#save : Nil
Saves rates to a JSON file.
-
#transaction(*, mutable : Bool = false, & : -> _)
Wraps block execution in a concurrency-safe transaction.
Constructor methods inherited from class Money::Currency::RateStore::Memory
new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)new(pull : JSON::PullParser) new
Class methods inherited from class Money::Currency::RateStore::Memory
key : String
key
Instance methods inherited from class Money::Currency::RateStore
<<(rate : Rate) : self<<(rates : Enumerable(Rate)) : self <<, [](base : String | Symbol | Currency, target : String | Symbol | Currency) : BigDecimal [], []=(base : String | Symbol | Currency, target : String | Symbol | Currency, value : Number) : Nil []=, []?(base : String | Symbol | Currency, target : String | Symbol | Currency) : BigDecimal | Nil []?, clear(base : Currency | Nil = nil, target : Currency | Nil = nil) : Nil clear, compact : Nil compact, each(*, include_stale : Bool = false, & : Rate -> ) : Nil each, rates : Array(Rate) rates, transaction(*, mutable : Bool = false, & : -> _) transaction, ttl : Time::Span | Nil ttl, ttl=(ttl : Time::Span | Nil) ttl=
Constructor methods inherited from class Money::Currency::RateStore
new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)new(pull : JSON::PullParser)
new(*, ttl : Time::Span | Nil = nil) new
Class methods inherited from class Money::Currency::RateStore
find(name : String | Symbol) : Money::Currency::RateStore.class
find,
find?(name : String | Symbol) : Money::Currency::RateStore.class | Nil
find?,
registry
registry
Constructor Detail
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
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
Class Method Detail
Instance Method Detail
Wraps block execution in a concurrency-safe transaction.