Class: Easydsl::Node

Inherits:
Object
  • Object
show all
Defined in:
lib/easydsl/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(name, args, index, parent, node_builders = []) ⇒ Node

Returns a new instance of Node.



6
7
8
9
10
11
12
13
# File 'lib/easydsl/node.rb', line 6

def initialize(name, args, index, parent, node_builders = [])
  @name = name.to_s.chomp('!').to_sym
  @singleton = name[-1] == '!'
  @args = args
  @index = index
  @parent = parent
  add_hierarchy(self, node_builders, 0)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_symbol, *args, &block) ⇒ Object (protected)



153
154
155
156
157
# File 'lib/easydsl/node.rb', line 153

def method_missing(method_symbol, *args, &block)
  return handle_block(method_symbol, *args, &block) if block_given?
  return handle_operators(method_symbol, *args) if method_symbol.to_s.end_with?('=', '?', '[]')
  handle_node(method_symbol, *args, &block)
end

Instance Method Details

#define(&block) ⇒ Object



49
50
51
# File 'lib/easydsl/node.rb', line 49

def define(&block)
  add_block(&block)
end

#get_all_nodesObject



19
20
21
22
23
# File 'lib/easydsl/node.rb', line 19

def get_all_nodes
  all = []
  nodes.each { |k, _v| all += nodes[k] }
  all.sort! { |a, b| a.get_index <=> b.get_index }
end

#get_argsObject



29
30
31
# File 'lib/easydsl/node.rb', line 29

def get_args
  @args
end

#get_indexObject



41
42
43
# File 'lib/easydsl/node.rb', line 41

def get_index
  @index
end

#get_max_indexObject



37
38
39
# File 'lib/easydsl/node.rb', line 37

def get_max_index
  get_all_nodes.map(&:get_index).max || 0
end

#get_nameObject



25
26
27
# File 'lib/easydsl/node.rb', line 25

def get_name
  @name
end

#get_nodesObject



15
16
17
# File 'lib/easydsl/node.rb', line 15

def get_nodes
  @nodes ||= Hash.new { |h, k| h[k] = NodeArray.new }
end

#get_parentObject



45
46
47
# File 'lib/easydsl/node.rb', line 45

def get_parent
  @parent
end

#is_singleton?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/easydsl/node.rb', line 53

def is_singleton?
  @singleton
end

#set_args(value) ⇒ Object



33
34
35
# File 'lib/easydsl/node.rb', line 33

def set_args(value)
  @args = value
end