Class: Babl::Operators::Each::EachNode

Inherits:
Object
  • Object
show all
Defined in:
lib/babl/operators/each.rb

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ EachNode

Returns a new instance of EachNode.



13
14
15
# File 'lib/babl/operators/each.rb', line 13

def initialize(node)
    @node = node
end

Instance Method Details

#dependenciesObject



17
18
19
# File 'lib/babl/operators/each.rb', line 17

def dependencies
    { __each__: node.dependencies }
end

#documentationObject



21
22
23
# File 'lib/babl/operators/each.rb', line 21

def documentation
    [node.documentation]
end

#pinned_dependenciesObject



25
26
27
# File 'lib/babl/operators/each.rb', line 25

def pinned_dependencies
    node.pinned_dependencies
end

#render(ctx) ⇒ Object



29
30
31
32
33
34
35
36
37
# File 'lib/babl/operators/each.rb', line 29

def render(ctx)
    collection = ctx.object

    unless collection.is_a?(Enumerable)
        raise RenderingError, "Object is not enumerable : #{collection.inspect}"
    end

    collection.each_with_index.map { |value, idx| node.render(ctx.move_forward(value, idx)) }
end