Class: DSeL::DSL::Nodes::APIBuilder

Inherits:
Direct show all
Defined in:
lib/dsel/dsl/nodes/api_builder.rb,
lib/dsel/dsl/nodes/api_builder/environment.rb

Defined Under Namespace

Modules: Environment

Constant Summary collapse

API_NODE =
DSeL::API::Node

Instance Attribute Summary

Attributes inherited from Base

#environment

Attributes inherited from Node

#parent, #root, #subject

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#cache_node, #nodes, #run, #shared_variables

Methods inherited from Node

#_dsel_node, #calc_node_hash, #hash, #root?

Constructor Details

#initialize(node, options = {}) ⇒ APIBuilder

Returns a new instance of APIBuilder.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# 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

Class Method Details

.build(*args, &block) ⇒ Object



10
11
12
13
14
15
16
# 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

Instance Method Details

#extend_envObject



61
62
63
64
65
# File 'lib/dsel/dsl/nodes/api_builder.rb', line 61

def extend_env
    [
        Environment
    ]
end

#node_for(subject, options = {}) ⇒ Object



47
48
49
50
51
52
# 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_methodsObject



54
55
56
57
58
59
# File 'lib/dsel/dsl/nodes/api_builder.rb', line 54

def reset_methods
    [
        :instance_variables,
        :method_missing
    ]
end