Class: Babl::Nodes::With

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

Instance Method Summary collapse

Instance Method Details

#dependenciesObject



12
13
14
15
16
17
18
19
# File 'lib/babl/nodes/with.rb', line 12

def dependencies
    Babl::Utils::Hash.deep_merge(
        node.dependencies[Parent::PARENT_MARKER] || Utils::Hash::EMPTY,
        nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b|
            Babl::Utils::Hash.deep_merge(a, b)
        }
    )
end

#optimizeObject



36
37
38
39
40
41
# File 'lib/babl/nodes/with.rb', line 36

def optimize
    optimized = node.optimize
    return optimized if Constant === optimized
    return optimized.node if Parent === optimized
    With.new(optimized, nodes.map(&:optimize), block)
end

#pinned_dependenciesObject



21
22
23
24
# File 'lib/babl/nodes/with.rb', line 21

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

#render(ctx) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/babl/nodes/with.rb', line 26

def render(ctx)
    values = nodes.map { |n| n.render(ctx) }
    value = begin
        block.arity.zero? ? ctx.object.instance_exec(&block) : block.call(*values)
    rescue StandardError => e
        raise Errors::RenderingError, "#{e.message}\n" + ctx.formatted_stack(:__block__), e.backtrace
    end
    node.render(ctx.move_forward(value, :__block__))
end

#schemaObject



8
9
10
# File 'lib/babl/nodes/with.rb', line 8

def schema
    node.schema
end