Module: MoneyAttribute::CurrencyCondition

Included in:
QueryMethods
Defined in:
lib/money_attribute/query/currency_condition.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#resolve_currency_condition(attr, currency) ⇒ ActiveRecord::Relation

Builds a currency filter for the registered money attribute.

Parameters:

  • attr (Symbol)

    the money attribute name

  • currency (String, Mint::Currency)

    the currency code or object

Returns:

  • (ActiveRecord::Relation)

Raises:

  • (ArgumentError)

    if the attribute is not a composite money attribute



12
13
14
15
16
17
18
19
20
21
# File 'lib/money_attribute/query/currency_condition.rb', line 12

def resolve_currency_condition(attr, currency)
  spec = money_attribute_spec!(attr)

  unless spec.composite?
    raise ArgumentError, "#{klass.name}.#{attr} is a money_amount attribute with no currency column"
  end

  code = currency.is_a?(Mint::Currency) ? currency.code : currency.to_s
  where(spec.currency_col => code)
end