Class: Puffer::Resource::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/puffer/resource/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTree

Returns a new instance of Tree.



6
7
8
# File 'lib/puffer/resource/tree.rb', line 6

def initialize
  @nodes = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



31
32
33
# File 'lib/puffer/resource/tree.rb', line 31

def method_missing method, *args, &block
  nodes.send method, *args, &block if nodes.respond_to? method
end

Instance Attribute Details

#nodesObject

Returns the value of attribute nodes.



4
5
6
# File 'lib/puffer/resource/tree.rb', line 4

def nodes
  @nodes
end

Instance Method Details

#append_node(*args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/puffer/resource/tree.rb', line 10

def append_node *args
  options = args.extract_options!
  parent = args.first

  parent = case parent
  when Integer then
    nodes[parent]
  when Puffer::Resource::Node, nil then
    parent
  else
    return
  end

  push Puffer::Resource::Node.new(parent, options)
  size.pred
end

#rootsObject



27
28
29
# File 'lib/puffer/resource/tree.rb', line 27

def roots
  nodes.select &:root?
end