class Babl::Rendering::Context

Attributes

freelist[RW]
key[RW]
object[RW]
parent[RW]
pins[RW]

Public Class Methods

new(freelist = []) click to toggle source
# File lib/babl/rendering/context.rb, line 10
def initialize(freelist = [])
    @freelist = freelist
end

Public Instance Methods

create_pin(ref) { |new_frame| ... } click to toggle source
# File lib/babl/rendering/context.rb, line 60
def create_pin(ref)
    new_frame = @freelist.pop || Context.new(freelist)

    new_frame.parent = parent
    new_frame.object = object
    new_frame.key = key
    new_frame.pins = (pins || Utils::Hash::EMPTY).merge(ref => new_frame)

    yield new_frame
ensure
    @freelist << new_frame
end
formatted_stack(*additional_stack_items) click to toggle source
# File lib/babl/rendering/context.rb, line 78
def formatted_stack(*additional_stack_items)
    stack_trace = ([:__root__] + stack + additional_stack_items).join('.')
    "BABL @ #{stack_trace}"
end
goto_pin(ref) { |new_frame| ... } click to toggle source
# File lib/babl/rendering/context.rb, line 43
def goto_pin(ref)
    current_pins = pins || Utils::Hash::EMPTY
    pin_frame = current_pins[ref]
    raise Errors::RenderingError, 'Pin reference cannot be used here' unless pin_frame

    new_frame = @freelist.pop || Context.new(freelist)

    new_frame.object = pin_frame.object
    new_frame.parent = pin_frame.parent
    new_frame.key = pin_frame.key
    new_frame.pins = (pin_frame.pins || Utils::Hash::EMPTY).merge(current_pins)

    yield new_frame
ensure
    @freelist << new_frame
end
move_backward() { |new_frame| ... } click to toggle source
# File lib/babl/rendering/context.rb, line 27
def move_backward
    new_frame = @freelist.pop || Context.new(freelist)

    parent_frame = parent
    raise Errors::RenderingError, 'There is no parent element' unless parent_frame

    new_frame.object = parent_frame.object
    new_frame.parent = parent_frame.parent
    new_frame.key = parent_frame.key
    new_frame.pins = pins

    yield new_frame
ensure
    @freelist << new_frame
end
move_forward(new_object, key) { |new_frame| ... } click to toggle source
# File lib/babl/rendering/context.rb, line 14
def move_forward(new_object, key)
    new_frame = @freelist.pop || Context.new(freelist)

    new_frame.object = new_object
    new_frame.key = key
    new_frame.parent = self
    new_frame.pins = pins

    yield new_frame
ensure
    @freelist << new_frame
end
stack() click to toggle source
# File lib/babl/rendering/context.rb, line 73
def stack
    parent_frame = parent
    (parent_frame ? parent_frame.stack : Utils::Array::EMPTY) + [key].compact
end