class Money::Currency::RateStore::File

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.cr

Constructors

Class Method Summary

Instance Method Summary

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

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

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

[View source]
def self.new(pull : JSON::PullParser) #

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

[View source]
def self.new(path : Path | String, *, ttl : Time::Span | Nil = nil) #

[View source]

Class Method Detail

def self.key : String #

Returns the class key.


[View source]

Instance Method Detail

def load : Nil #

Loads rates from a JSON file.


[View source]
def path : Path #

[View source]
def path=(path : Path) #

[View source]
def save : Nil #

Saves rates to a JSON file.


[View source]
def transaction(*, mutable : Bool = false, & : -> _) #

Wraps block execution in a concurrency-safe transaction.


[View source]