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

Instance Method Summary

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

def self.new(filepath : Path | String, ttl : Time::Span | Nil = nil) #

[View source]

Instance Method Detail

def load : Nil #

Loads rates from a JSON file.


[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]