Sha256: 39ea4a57c434f35251f34763d2f4a3ccff6a140b388c096c69ae6f8612979d5a

Contents?: true

Size: 497 Bytes

Versions: 4

Compression:

Stored size: 497 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
        ExchangeRate.all
      end
    end

    class ExchangeRate < ::ActiveRecord::Base
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
danconia-0.2.5 lib/danconia/stores/active_record.rb
danconia-0.2.4 lib/danconia/stores/active_record.rb
danconia-0.2.3 lib/danconia/stores/active_record.rb
danconia-0.2.2 lib/danconia/stores/active_record.rb