Module: MoneyAttribute::AmountOrder Private

Included in:
QueryMethods
Defined in:
lib/money_attribute/query/amount_order.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 ordering resolution for the order_by_amount query helper.

Instance Method Summary collapse

Instance Method Details

#resolve_amount_order(attr, direction) ⇒ 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 an amount ordering for the registered money attribute.

Composite attributes order by currency ASC first, then amount in the requested direction. Single-column attributes order by amount only.

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



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

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

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