Module: MoneyAttribute::CurrencyCondition Private

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

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Internal currency-filter resolution for the where_currency query helper.

Instance Method Summary collapse

Instance Method Details

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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Builds a currency filter for the registered money attribute.

Only composite attributes have a currency column, so single-column attributes raise.

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



18
19
20
21
22
23
24
25
26
27
# File 'lib/money_attribute/query/currency_condition.rb', line 18

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_column => code)
end