Module: MoneyAttribute::QueryHelpers Private

Included in:
QueryMethods
Defined in:
lib/money_attribute/query/helpers.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 helpers shared by the query sub-modules.

Instance Method Summary collapse

Instance Method Details

#extract_money_row(row, specs) ⇒ Array

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.

Extracts money values for all specs from a single result row.

Parameters:

  • row (Array)

    the flat row from pluck or pick

  • specs (Array<AttributeSpec>)

    the money attribute specs

Returns:

  • (Array)

    the extracted money values



27
28
29
30
31
32
33
34
# File 'lib/money_attribute/query/helpers.rb', line 27

def extract_money_row(row, specs)
  cursor = 0

  specs.map do |spec|
    value, cursor = extract_attribute_value(row, spec, cursor)
    value
  end
end

#money_attribute_spec!(attr) ⇒ AttributeSpec

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.

Returns the registered money attribute spec or raises when missing.

Parameters:

  • attr (Symbol, String)

    the money attribute name

Returns:

Raises:

  • (ArgumentError)

    if the attribute is not registered



14
15
16
17
18
19
# File 'lib/money_attribute/query/helpers.rb', line 14

def money_attribute_spec!(attr)
  spec = klass.money_attribute_spec(attr)
  raise ArgumentError, "#{attr} is not a money attribute on #{klass.name}" unless spec

  spec
end