Module: MoneyAttribute::QueryHelpers

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

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#extract_pick_value(row, spec, cursor) ⇒ Array(Object, Integer)

Extracts a single value from a flat row at the given cursor position.

Parameters:

  • row (Array)

    the flat row from pluck or pick

  • spec (AttributeSpec)

    the money attribute spec

  • cursor (Integer)

    current position in the row array

Returns:

  • (Array(Object, Integer))

    the extracted value and updated cursor



24
25
26
27
28
# File 'lib/money_attribute/query/helpers.rb', line 24

def extract_pick_value(row, spec, cursor)
  return [row[cursor], cursor + 1] if spec.single?

  [spec.build_money(row[cursor], row[cursor + 1]), cursor + 2]
end

#money_attribute_spec!(attr) ⇒ AttributeSpec

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



11
12
13
14
15
16
# File 'lib/money_attribute/query/helpers.rb', line 11

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