Module: SemanticPuppet::Dependency::GraphNode
- Includes:
- Comparable
- Included in:
- Graph, ModuleRelease
- Defined in:
- lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb
Instance Method Summary collapse
- #<<(nodes) ⇒ Object
- #<=>(other) ⇒ Object
-
#add_constraint(source, mod, desc) {|node| ... } ⇒ void
Constrains the named module to suitable releases, as determined by the given block.
-
#add_dependency(name) ⇒ void
Adds the given dependency name to the list of dependencies.
- #children ⇒ Object
- #constraints ⇒ Object
- #constraints_for(name) ⇒ Object
-
#dependencies ⇒ { String => SortedSet<GraphNode> }
The satisfactory dependency nodes.
-
#dependency_names ⇒ Array<String>
The list of dependency names.
- #name ⇒ Object
- #populate_children(nodes) ⇒ Object
-
#satisfied? ⇒ Boolean
Determines whether the modules dependencies are satisfied by the known releases.
- #satisfies_constraints?(release) ⇒ Boolean
- #satisfies_dependency?(node) ⇒ Boolean
Instance Method Details
#<<(nodes) ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 101 def << (nodes) Array(nodes).each do |node| next unless dependencies.key?(node.name) if satisfies_dependency?(node) dependencies[node.name] << node end end return self end |
#<=>(other) ⇒ Object
112 113 114 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 112 def <=>(other) name <=> other.name end |
#add_constraint(source, mod, desc) {|node| ... } ⇒ void
This method returns an undefined value.
Constrains the named module to suitable releases, as determined by the given block.
88 89 90 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 88 def add_constraint(source, mod, desc, &block) constraints["#{mod}"] << [ source, desc, block ] end |
#add_dependency(name) ⇒ void
This method returns an undefined value.
Adds the given dependency name to the list of dependencies.
46 47 48 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 46 def add_dependency(name) dependencies[name] end |
#children ⇒ Object
20 21 22 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 20 def children @_children ||= {} end |
#constraints ⇒ Object
55 56 57 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 55 def constraints @_constraints ||= Hash.new { |h, k| h[k] = [] } end |
#constraints_for(name) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 59 def constraints_for(name) return [] unless constraints.has_key?(name) constraints[name].map do |constraint| { :source => constraint[0], :description => constraint[1], :test => constraint[2], } end end |
#dependencies ⇒ { String => SortedSet<GraphNode> }
Returns the satisfactory dependency nodes.
38 39 40 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 38 def dependencies @_dependencies ||= Hash.new { |h, k| h[k] = SortedSet.new } end |
#dependency_names ⇒ Array<String>
Returns the list of dependency names.
51 52 53 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 51 def dependency_names dependencies.keys end |
#name ⇒ Object
9 10 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 9 def name end |
#populate_children(nodes) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 24 def populate_children(nodes) if children.empty? nodes = nodes.select { |node| satisfies_dependency?(node) } nodes.each do |node| children[node.name] = node node.populate_children(nodes) end self.freeze end end |
#satisfied? ⇒ Boolean
Determines whether the modules dependencies are satisfied by the known releases.
16 17 18 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 16 def satisfied? dependencies.none? { |_, v| v.empty? } end |
#satisfies_constraints?(release) ⇒ Boolean
97 98 99 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 97 def satisfies_constraints?(release) constraints_for(release.name).all? { |x| x[:test].call(release) } end |
#satisfies_dependency?(node) ⇒ Boolean
92 93 94 |
# File 'lib/puppet/vendor/semantic_puppet/lib/semantic_puppet/dependency/graph_node.rb', line 92 def satisfies_dependency?(node) dependencies.key?(node.name) && satisfies_constraints?(node) end |