class DSeL::DSL::Nodes::APIBuilder

Constants

API_NODE

Public Class Methods

build( *args, &block ) click to toggle source
# File lib/dsel/dsl/nodes/api_builder.rb, line 10
def self.build( *args, &block )
    fail ArgumentError, 'Missing block.' if !block

    node = new( *args )
    node.run( &block )
    node.subject
end
new( node, options = {} ) click to toggle source
Calls superclass method DSeL::DSL::Nodes::Base::new
# File lib/dsel/dsl/nodes/api_builder.rb, line 20
def initialize( node, options = {} )
    @superclass = options[:superclass] || API_NODE
    if !(@superclass <= API_NODE)
        fail ArgumentError, "Superclass not subclass of #{API_NODE}."
    end

    if node.is_a?( Symbol )
        namespace = options[:namespace]  || Object

        if namespace.constants.include?( node )
            fail ArgumentError, "Node name taken: #{c.inspect}"
        end

        subject = namespace.const_set( node, Class.new( @superclass ) )

    elsif node.is_a?( Class ) && node < DSeL::API::Node
        subject = node

    else
        fail ArgumentError,
             "Expected #{Symbol} or #{DSeL::API::Node}, got: #{node.inspect}"
    end

    super( subject, options )
end

Public Instance Methods

extend_env() click to toggle source
# File lib/dsel/dsl/nodes/api_builder.rb, line 61
def extend_env
    [
        Environment
    ]
end
node_for( subject, options = {} ) click to toggle source

@private

Calls superclass method DSeL::DSL::Nodes::Base#node_for
# File lib/dsel/dsl/nodes/api_builder.rb, line 47
def node_for( subject, options = {} )
    super( subject, options.merge(
        namespace:  @subject,
        superclass: @superclass
    ))
end
reset_methods() click to toggle source
# File lib/dsel/dsl/nodes/api_builder.rb, line 54
def reset_methods
    [
        :instance_variables,
        :method_missing
    ]
end