Class: Alf::Engine::ToArray
- Inherits:
-
Object
- Object
- Alf::Engine::ToArray
- 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
-
#operand ⇒ Enumerable
readonly
The operand.
-
#ordering ⇒ Ordering
readonly
The ordering info.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each(&block) ⇒ Object
- #arguments ⇒ Object
-
#initialize(operand, ordering = nil, expr = nil, compiler = nil) ⇒ ToArray
constructor
Creates an ToArray instance.
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
#operand ⇒ Enumerable (readonly)
Returns The operand.
23 24 25 |
# File 'lib/alf/engine/to_array.rb', line 23 def operand @operand end |
#ordering ⇒ Ordering (readonly)
Returns The ordering info.
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 |
#arguments ⇒ Object
43 44 45 |
# File 'lib/alf/engine/to_array.rb', line 43 def arguments [ ordering ] end |