Class: Babl::Operators::With::WithNode

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

Instance Method Summary collapse

Constructor Details

#initialize(node, nodes, block) ⇒ WithNode

Returns a new instance of WithNode.



19
20
21
22
23
# File 'lib/babl/operators/with.rb', line 19

def initialize(node, nodes, block)
    @node = node
    @nodes = nodes
    @block = block
end

Instance Method Details

#dependenciesObject



29
30
31
32
# File 'lib/babl/operators/with.rb', line 29

def dependencies
    # Dependencies of 'node' are explicitely ignored
    nodes.map(&:dependencies).reduce({}) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
end

#documentationObject



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

def documentation
    node.documentation
end

#pinned_dependenciesObject



34
35
36
# File 'lib/babl/operators/with.rb', line 34

def pinned_dependencies
    (nodes + [node]).map(&:pinned_dependencies).reduce({}) { |a, b| Babl::Utils::Hash.deep_merge(a, b) }
end

#render(ctx) ⇒ Object



38
39
40
41
42
43
# File 'lib/babl/operators/with.rb', line 38

def render(ctx)
    values = nodes.map { |n| n.render(ctx) }
    node.render(ctx.move_forward_block(:__block__) do
        block.arity.zero? ? ctx.object.instance_exec(&block) : block.call(*values)
    end)
end