Module: MoneyAttribute::AmountOrder

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#resolve_amount_order(attr, direction) ⇒ ActiveRecord::Relation

Builds an amount ordering for the registered money attribute.

Parameters:

  • attr (Symbol)

    the money attribute name

  • direction (Symbol)

    :asc or :desc

Returns:

  • (ActiveRecord::Relation)

Raises:

  • (ArgumentError)

    if the attribute is not a registered money attribute



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

def resolve_amount_order(attr, direction)
  spec = money_attribute_spec!(attr)

  if spec.composite?
    order(spec.currency_col => :asc, spec.amount_col => direction)
  else
    order(spec.amount_col => direction)
  end
end