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



12
13
14
# File 'lib/arver/partition_hierarchy_node.rb', line 12

def name
  @name
end

#parentObject

Returns the value of attribute parent.



5
6
7
# File 'lib/arver/partition_hierarchy_node.rb', line 5

def parent
  @parent
end

Instance Method Details

#==(other_node) ⇒ Object



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

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

#add_child(child) ⇒ Object



29
30
31
# File 'lib/arver/partition_hierarchy_node.rb', line 29

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

#child(name) ⇒ Object



33
34
35
# File 'lib/arver/partition_hierarchy_node.rb', line 33

def child(name)
  children[name]
end

#childrenObject



25
26
27
# File 'lib/arver/partition_hierarchy_node.rb', line 25

def children
  @children ||= {}
end

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

Yields:

  • (_self)

Yield Parameters:



37
38
39
40
41
42
# File 'lib/arver/partition_hierarchy_node.rb', line 37

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

#each_partition(&blk) ⇒ Object



44
45
46
47
48
# File 'lib/arver/partition_hierarchy_node.rb', line 44

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

#find(name) ⇒ Object



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

def find( name )
  found = []
  self.each_node do | node |
    found += [ node ] if (node.name == name || node.path =~ /#{name}$/)
  end
  found
end

#has_child?(child) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


64
65
66
67
68
# File 'lib/arver/partition_hierarchy_node.rb', line 64

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



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

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

#pathObject



16
17
18
# File 'lib/arver/partition_hierarchy_node.rb', line 16

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

#run_action(action) ⇒ Object



104
105
106
107
108
# File 'lib/arver/partition_hierarchy_node.rb', line 104

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

#target?(list) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
53
54
# File 'lib/arver/partition_hierarchy_node.rb', line 50

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

#to_asciiObject



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

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



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

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