Module: Arver::PartitionHierarchyNode

Included in:
Host, Hostgroup, Partition, Tree
Defined in:
lib/arver/partition_hierarchy_node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#nameObject



14
15
16
# File 'lib/arver/partition_hierarchy_node.rb', line 14

def name
  @name
end

#parentObject

Returns the value of attribute parent.



7
8
9
# File 'lib/arver/partition_hierarchy_node.rb', line 7

def parent
  @parent
end

Instance Method Details

#==(other_node) ⇒ Object



89
90
91
92
93
94
95
# File 'lib/arver/partition_hierarchy_node.rb', line 89

def == other_node
  equals = true
  children.each do | name, child |
    equals &= child == other_node.child( name )
  end
  equals
end

#add_child(child) ⇒ Object



31
32
33
# File 'lib/arver/partition_hierarchy_node.rb', line 31

def add_child(child)
  children[child.name] = child
end

#child(name) ⇒ Object



35
36
37
# File 'lib/arver/partition_hierarchy_node.rb', line 35

def child(name)
  children[name]
end

#childrenObject



27
28
29
# File 'lib/arver/partition_hierarchy_node.rb', line 27

def children
  @children ||= {}
end

#each_node {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



39
40
41
42
43
44
# File 'lib/arver/partition_hierarchy_node.rb', line 39

def each_node(&blk)
  yield self
  children.each_value do | child |
    child.each_node(&blk)
  end
end

#each_partition(&blk) ⇒ Object



46
47
48
49
50
# File 'lib/arver/partition_hierarchy_node.rb', line 46

def each_partition(&blk)
  children.each_value do | child |
    child.each_partition(&blk)
  end
end

#find(name) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/arver/partition_hierarchy_node.rb', line 72

def find( name )
  found = []
  self.each_node do | node |
    found += [ node ] if ( node.name == name || node.path.ends_with?( name ) )
  end
  found
end

#has_child?(child) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
61
62
63
64
# File 'lib/arver/partition_hierarchy_node.rb', line 58

def has_child?( child )
  return true if self.equal?( child )
  children.each_value do | my_child |
    return true if my_child.has_child?( child )
  end
  false
end

#has_parent?(node) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
# File 'lib/arver/partition_hierarchy_node.rb', line 66

def has_parent?( node )
  return true if self.equal?( node )
  return false if parent.nil?
  return self.parent.has_parent?( node )
end

#initialize(a_name, parent_node) ⇒ Object



9
10
11
12
# File 'lib/arver/partition_hierarchy_node.rb', line 9

def initialize(a_name, parent_node)
  @name = a_name
  self.parent = parent_node
end

#pathObject



18
19
20
# File 'lib/arver/partition_hierarchy_node.rb', line 18

def path
  parent.path<<"/"<<@name
end

#run_action(action) ⇒ Object



106
107
108
109
110
# File 'lib/arver/partition_hierarchy_node.rb', line 106

def run_action( action )
  self.children.each_value do | child |
    action.run_on( child )
  end
end

#target?(list) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/arver/partition_hierarchy_node.rb', line 52

def target?( list )
  list.any? do |target|
    self.has_child?( target ) || self.has_parent?( target )
  end
end

#to_asciiObject



80
81
82
83
84
85
86
87
# File 'lib/arver/partition_hierarchy_node.rb', line 80

def to_ascii
  list = ""
  children.each do | name, child |
    list += "+- "+name+"\n"
    list += ( child.to_ascii.indent_once ) +"\n" unless child.to_ascii.empty?
  end
  list.chop
end

#to_yamlObject



97
98
99
100
101
102
103
104
# File 'lib/arver/partition_hierarchy_node.rb', line 97

def to_yaml
  yaml = ""
  children.each do | name, child |
    yaml += "'"+name+"':\n"
    yaml += ( child.to_yaml.indent_once ) +"\n"
  end
  yaml.chop
end