Sha256: df55bc2c6c798395a5262d93e954714b486b8f4f863fa0215fee651074462a70

Contents?: true

Size: 905 Bytes

Versions: 43

Compression:

Stored size: 905 Bytes

Contents

require 'money/bank/base'

class Money
  module Bank
    # Raised when trying to exchange currencies
    class DifferentCurrencyError < Error; end

    # Class to ensure client code is operating in a single currency
    # by raising if an exchange attempts to happen.
    #
    # This is useful when an application uses multiple currencies but
    # it usually deals with only one currency at a time so any arithmetic
    # where exchanges happen are erroneous. Using this as the default bank
    # means that that these mistakes don't silently do the wrong thing.
    class SingleCurrency < Base

      # Raises a DifferentCurrencyError to remove possibility of accidentally
      # exchanging currencies
      def exchange_with(from, to_currency, &block)
        raise DifferentCurrencyError, "No exchanging of currencies allowed: #{from} #{from.currency} to #{to_currency}"
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 2 rubygems

Version Path
money-6.19.0 lib/money/bank/single_currency.rb
money-6.18.0 lib/money/bank/single_currency.rb
money-6.17.0 lib/money/bank/single_currency.rb
money-6.16.0 lib/money/bank/single_currency.rb
money-6.14.1 lib/money/bank/single_currency.rb
money-6.14.0 lib/money/bank/single_currency.rb
money-6.13.8 lib/money/bank/single_currency.rb
money-6.13.7 lib/money/bank/single_currency.rb
money-6.13.6 lib/money/bank/single_currency.rb
money-6.13.5 lib/money/bank/single_currency.rb
money-6.13.4 lib/money/bank/single_currency.rb
money-6.13.3 lib/money/bank/single_currency.rb
money-6.13.2 lib/money/bank/single_currency.rb
money-6.13.1 lib/money/bank/single_currency.rb
money-6.13.0 lib/money/bank/single_currency.rb
money-6.12.0 lib/money/bank/single_currency.rb
money-6.11.3 lib/money/bank/single_currency.rb
money-6.11.2 lib/money/bank/single_currency.rb
money-6.11.1 lib/money/bank/single_currency.rb
money-6.11.0 lib/money/bank/single_currency.rb