Class: Alf::Engine::ToArray

Inherits:
Object
  • Object
show all
Includes:
Cog
Defined in:
lib/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 => [...] }
#    ]

Constant Summary

Constants included from Cog

Cog::EMPTY_CHILDREN, Cog::EMPTY_OPTIONS

Instance Attribute Summary collapse

Attributes included from Compiler::Cog

#compiler, #expr

Instance Method Summary collapse

Methods included from Cog

#children, #each, #options, #to_s

Methods included from Compiler::Cog

#cog_orders, #orderedby?, #relation_type, #to_ascii_tree, #to_cog, #to_relation

Constructor Details

#initialize(operand, ordering = nil, expr = nil, compiler = nil) ⇒ ToArray

Creates an ToArray instance


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

def initialize(operand, ordering = nil, expr = nil, compiler = nil)
  super(expr, compiler)
  @operand = operand
  @ordering = ordering
end

Instance Attribute Details

#operandEnumerable (readonly)


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

def operand
  @operand
end

#orderingOrdering (readonly)


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

def ordering
  @ordering
end

Instance Method Details

#_each(&block) ⇒ Object


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

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

#argumentsObject


43
44
45
# File 'lib/alf/engine/to_array.rb', line 43

def arguments
  [ ordering ]
end