Sha256: dc1ca4306eb48d8d53da0a5476cb50f1851c3ce530444f3a23f5731b501368e0
Contents?: true
Size: 535 Bytes
Versions: 3
Compression:
Stored size: 535 Bytes
Contents
module Danconia module Stores class ActiveRecord def save_rates rates ExchangeRate.transaction do rates.each do |pair, rate| ExchangeRate.where(pair: pair).first_or_initialize.update rate: rate end end end def direct_rate from, to ExchangeRate.find_by(pair: [from, to].join)&.rate end def rates Hash[ExchangeRate.all.map { |er| [er.pair, er.rate] }] end end class ExchangeRate < ::ActiveRecord::Base end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
danconia-0.2.8 | lib/danconia/stores/active_record.rb |
danconia-0.2.7 | lib/danconia/stores/active_record.rb |
danconia-0.2.6 | lib/danconia/stores/active_record.rb |