class DSeL::DSL::Nodes::Base

Attributes

environment[R]

@return [Environment]

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/dsel/dsl/nodes/base.rb, line 11
def initialize(*)
    super

    @shared_variables = {}
    @nodes            = {}

    cache_node( self )
end

Public Instance Methods

cache_node( node ) click to toggle source

@private

# File lib/dsel/dsl/nodes/base.rb, line 30
def cache_node( node )
    nodes[node.hash] ||= node
end
node_for( subject, options = {} ) click to toggle source

@private

# File lib/dsel/dsl/nodes/base.rb, line 35
def node_for( subject, options = {} )
    nodes[calc_node_hash( subject )] ||=
        self.class.new( subject, options.merge( parent: self ) )
end
nodes() click to toggle source

@private

# File lib/dsel/dsl/nodes/base.rb, line 21
def nodes
    root? ? @nodes : @root.nodes
end
run( script = nil, &block ) click to toggle source
# File lib/dsel/dsl/nodes/base.rb, line 40
def run( script = nil, &block )
    if script && block
        fail ArgumentError, 'Cannot use both script and &block.'
    end

    begin
        prepare

        calling do
            if block
                return @environment.instance_eval( &block )
            end

            if script
                @environment.instance_eval do
                    return eval( IO.read( script ) )
                end
            end
        end
    ensure
        # Re-entry, don't touch anything.
        return if calling?

        # May not have been prepared yet.
        return if !@environment.respond_to?( Environment::DSEL_NODE_ACCESSOR )

        cleanup
    end
end
shared_variables() click to toggle source
# File lib/dsel/dsl/nodes/base.rb, line 25
def shared_variables
    root? ? @shared_variables : @root.shared_variables
end

Private Instance Methods

calling( &block ) click to toggle source
# File lib/dsel/dsl/nodes/base.rb, line 91
def calling( &block )
    return block.call if @calling

    @calling = true
    begin
        block.call
    ensure
        @calling = false
    end
end
calling?() click to toggle source
# File lib/dsel/dsl/nodes/base.rb, line 102
def calling?
    @calling
end
cleanup() click to toggle source
# File lib/dsel/dsl/nodes/base.rb, line 77
def cleanup
    @environment._dsel_node = nil
    cleanup_environment
end
cleanup_environment() click to toggle source

@abstract

# File lib/dsel/dsl/nodes/base.rb, line 83
def cleanup_environment
end
prepare() click to toggle source
# File lib/dsel/dsl/nodes/base.rb, line 72
def prepare
    prepare_environment
    @environment._dsel_node = self
end
prepare_environment() click to toggle source

@abstract

# File lib/dsel/dsl/nodes/base.rb, line 87
def prepare_environment
    fail 'Not implemented.'
end