Class: Alf::Engine::ToArray

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/alf-engine/alf/engine/to_array.rb

Overview

Ensures an order of tuples, recursing on relation value attributes, that are converted as arrays as well.

Example:

res = [
  {:price => 12.0, :rva => Relation(...)},
  {:price => 10.0, :rva => Relation(...)}
]
ToArray.new(res, [:price, :asc]).to_a
# => [
#      {:price => 10.0, :rva => [...] },
#      {:price => 12.0, :rva => [...] }
#    ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Cog

#each, #to_dot, #to_relation

Constructor Details

#initialize(operand, ordering) ⇒ ToArray

Creates an ToArray instance



29
30
31
32
# File 'lib/alf-engine/alf/engine/to_array.rb', line 29

def initialize(operand, ordering)
  @operand = operand
  @ordering = ordering
end

Instance Attribute Details

#operandEnumerable (readonly)

Returns The operand.

Returns:

  • (Enumerable)

    The operand



23
24
25
# File 'lib/alf-engine/alf/engine/to_array.rb', line 23

def operand
  @operand
end

#orderingOrdering (readonly)

Returns The ordering info.

Returns:

  • (Ordering)

    The ordering info



26
27
28
# File 'lib/alf-engine/alf/engine/to_array.rb', line 26

def ordering
  @ordering
end

Instance Method Details

#_each(&block) ⇒ Object



35
36
37
38
39
# File 'lib/alf-engine/alf/engine/to_array.rb', line 35

def _each(&block)
  Sort.new(operand, ordering).each do |tuple|
    yield recurse(tuple)
  end
end