Class: Alf::Engine::SetAttr
- Inherits:
-
Object
- Object
- Alf::Engine::SetAttr
- 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
-
#computation ⇒ TupleComputation
readonly
Computed attributes as a computation.
-
#operand ⇒ Enumerable
readonly
The operand.
Attributes included from Compiler::Cog
Instance Method Summary collapse
- #_each ⇒ Object
- #arguments ⇒ Object
-
#initialize(operand, computation, expr = nil, compiler = nil) ⇒ SetAttr
constructor
Creates a SetAttr 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, 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
#computation ⇒ TupleComputation (readonly)
28 29 30 |
# File 'lib/alf/engine/set_attr.rb', line 28 def computation @computation end |
#operand ⇒ Enumerable (readonly)
25 26 27 |
# File 'lib/alf/engine/set_attr.rb', line 25 def operand @operand end |
Instance Method Details
#_each ⇒ Object
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 |
#arguments ⇒ Object
46 47 48 |
# File 'lib/alf/engine/set_attr.rb', line 46 def arguments [ computation ] end |