Class: Alf::Engine::SetAttr

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

Overview

Set computed tuples attributes. This cog allows implementing both EXTEND and UPDATE relational operators.

Example:

rel = [
  {:name => "Jones", :city => "London"}
]
comp = TupleComputation[
  :city   => lambda{ city.upcase },
  :concat => lambda{ "#{name} #{city}" }
]
SetAttr.new(rel, comp).to_a
# => [
#      {:name => "Jones", :city => "LONDON", :concat => "Jones LONDON"}
#    ]

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, computation, expr = nil, compiler = nil) ⇒ SetAttr

Creates a SetAttr instance


31
32
33
34
35
# File 'lib/alf/engine/set_attr.rb', line 31

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

Instance Attribute Details

#computationTupleComputation (readonly)

Returns Computed attributes as a computation

Returns:

  • (TupleComputation)

    Computed attributes as a computation


28
29
30
# File 'lib/alf/engine/set_attr.rb', line 28

def computation
  @computation
end

#operandEnumerable (readonly)

Returns The operand

Returns:

  • (Enumerable)

    The operand


25
26
27
# File 'lib/alf/engine/set_attr.rb', line 25

def operand
  @operand
end

Instance Method Details

#_eachObject


38
39
40
41
42
43
44
# File 'lib/alf/engine/set_attr.rb', line 38

def _each
  scope = tuple_scope
  operand.each do |tuple|
    t = scope.__set_tuple(tuple)
    yield tuple.merge(@computation.evaluate(t))
  end
end

#argumentsObject


46
47
48
# File 'lib/alf/engine/set_attr.rb', line 46

def arguments
  [ computation ]
end