module DSeL::API::Node::ClassMethods
Public Instance Methods
branch()
click to toggle source
# File lib/dsel/api/node.rb, line 142 def branch t = { definers: self.definers, call_handlers: self.call_handlers.map { |h| c = h.dup; c.delete( :method ); c }, children: {} } self.children.each do |name, child| t[:children][name] = child.merge( child[:node].branch ) end t end
call_handlers()
click to toggle source
# File lib/dsel/api/node.rb, line 55 def call_handlers @call_handlers ||= [] end
child?()
click to toggle source
# File lib/dsel/api/node.rb, line 63 def child? !root? end
children()
click to toggle source
# File lib/dsel/api/node.rb, line 134 def children @children ||= {} end
configure( options, &block )
click to toggle source
# File lib/dsel/api/node.rb, line 43 def configure( options, &block ) @last_options = [options, block].compact end
define( *types )
click to toggle source
# File lib/dsel/api/node.rb, line 15 def define( *types ) if types.size > 1 if has_options? fail ArgumentError, "Cannot set options for multiple types: #{types}" end if has_description? fail ArgumentError, "Cannot set description for multiple types: #{types}" end end Generator.define_definers( self, *types ) end
definers()
click to toggle source
# File lib/dsel/api/node.rb, line 47 def definers @definers ||= [] end
describe( description )
click to toggle source
# File lib/dsel/api/node.rb, line 39 def describe( description ) @last_description = description end
flush_description()
click to toggle source
@private
# File lib/dsel/api/node.rb, line 157 def flush_description d = @last_description @last_description = nil d end
flush_options()
click to toggle source
@private
# File lib/dsel/api/node.rb, line 164 def flush_options o = @last_options @last_options = nil o end
has_call_handler?( type, *possible_object )
click to toggle source
# File lib/dsel/api/node.rb, line 51 def has_call_handler?( type, *possible_object ) method_defined? Generator.call_handler_name( type, *possible_object ) end
has_description?()
click to toggle source
# File lib/dsel/api/node.rb, line 35 def has_description? !!@last_description end
has_options?()
click to toggle source
# File lib/dsel/api/node.rb, line 31 def has_options? !!@last_options end
method_missing( m, *args, &block )
click to toggle source
Calls superclass method
# File lib/dsel/api/node.rb, line 224 def method_missing( m, *args, &block ) ms = m.to_s if ms.start_with? 'def_' to_define = ms.split( 'def_', 2 ).last define to_define send m, *args, &block else super( m, *args, &block ) end end
parent()
click to toggle source
# File lib/dsel/api/node.rb, line 79 def parent @parent end
push_call_handler( type, method, *possible_object )
click to toggle source
@private
# File lib/dsel/api/node.rb, line 171 def push_call_handler( type, method, *possible_object ) handler = { type: type.to_sym } if !possible_object.empty? handler.merge!( object: possible_object.first ) end if (options = self.flush_options) handler.merge!( options: options ) end if (description = self.flush_description) handler.merge!( description: description ) end handler.merge!( method: method.to_sym ) call_handlers << handler handler end
push_child( name, node, s = nil )
click to toggle source
# File lib/dsel/api/node.rb, line 91 def push_child( name, node, s = nil ) if s && !s.is_a?( Symbol ) && !s.respond_to?( :call ) fail ArgumentError, 'Subject not Symbol nor responds to #call.' end node.set_parent( self ) child = { name: name.to_sym, node: node } if (options = self.flush_options) child.merge!( options: options ) end if (description = self.flush_description) child.merge!( description: description ) end children[name] = child define_method name do ivar = "@#{name}" v = instance_variable_get( ivar ) return v if v sub = @subject if s.is_a?( Symbol ) sub = sub.send( s ) end if s.respond_to?( :call ) sub = s.call( sub ) end instance_variable_set( ivar, node.new( sub, parent: self ) ) end child end
push_children( c )
click to toggle source
# File lib/dsel/api/node.rb, line 83 def push_children( c ) c.each do |name, (klass, *args)| push_child( name, klass, *args ) end nil end
push_definer( type, method )
click to toggle source
@private
# File lib/dsel/api/node.rb, line 203 def push_definer( type, method ) definer = { type: type.to_sym } if (options = self.flush_options) definer.merge!( options: options ) end if (description = self.flush_description) definer.merge!( description: description ) end definer.merge!( method: method.to_sym ) definers << definer definer end
root()
click to toggle source
# File lib/dsel/api/node.rb, line 67 def root return self if root? @root ||= begin p = @parent while p.parent p = p.parent end p end end
root?()
click to toggle source
# File lib/dsel/api/node.rb, line 59 def root? !parent end
run( *args, &block )
click to toggle source
# File lib/dsel/api/node.rb, line 11 def run( *args, &block ) DSL::Nodes::API.new( new ).run( *args, &block ) end
set_parent( node )
click to toggle source
@private
# File lib/dsel/api/node.rb, line 197 def set_parent( node ) fail if @parent @parent = node end
tree()
click to toggle source
# File lib/dsel/api/node.rb, line 138 def tree root.branch end