Class: Babl::Nodes::With
- Inherits:
-
Object
- Object
- Babl::Nodes::With
- Defined in:
- lib/babl/nodes/with.rb
Instance Method Summary collapse
- #dependencies ⇒ Object
- #optimize ⇒ Object
- #pinned_dependencies ⇒ Object
- #render(ctx) ⇒ Object
- #schema ⇒ Object
Instance Method Details
#dependencies ⇒ Object
12 13 14 15 |
# File 'lib/babl/nodes/with.rb', line 12 def dependencies # Dependencies of 'node' are explicitely ignored nodes.map(&:dependencies).reduce(Utils::Hash::EMPTY) { |a, b| Babl::Utils::Hash.deep_merge(a, b) } end |
#optimize ⇒ Object
32 33 34 35 36 |
# File 'lib/babl/nodes/with.rb', line 32 def optimize optimized = node.optimize return optimized if Constant === optimized With.new(optimized, nodes.map(&:optimize), block) end |
#pinned_dependencies ⇒ Object
17 18 19 20 |
# File 'lib/babl/nodes/with.rb', line 17 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
22 23 24 25 26 27 28 29 30 |
# File 'lib/babl/nodes/with.rb', line 22 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.}\n" + ctx.formatted_stack(:__block__), e.backtrace end node.render(ctx.move_forward(value, :__block__)) end |
#schema ⇒ Object
8 9 10 |
# File 'lib/babl/nodes/with.rb', line 8 def schema node.schema end |