Class: Souffle::Node
- Inherits:
-
Object
- Object
- Souffle::Node
- Defined in:
- lib/souffle/node.rb,
lib/souffle/node.rb
Overview
A node object that’s part of a given system.
Defined Under Namespace
Classes: RunList, RunListItem, RunListParser
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#dependencies ⇒ Object
Returns the value of attribute dependencies.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parents ⇒ Object
Returns the value of attribute parents.
-
#provisioner ⇒ Object
Returns the value of attribute provisioner.
-
#run_list ⇒ Object
Returns the value of attribute run_list.
-
#system ⇒ Object
Returns the value of attribute system.
Instance Method Summary collapse
-
#add_child(node) ⇒ Object
Adds a child node to the current node.
-
#depends_on?(node) ⇒ Array
Check whether or not a given node depends on another node.
-
#domain ⇒ String
The top-level domain name for the given node.
-
#each_child {|Souffle::Node, NilClass| ... } ⇒ Object
Iterator method for children.
-
#eql?(other) ⇒ Boolean
Equality comparator for nodes.
-
#fqdn ⇒ String
The fully qualified domain name for the given node.
-
#initialize(parent_multiplier = 5) ⇒ Node
constructor
Creates a new souffle node with bare dependencies and run_list.
-
#log_prefix ⇒ String
The logging prefix for the given node.
-
#provider ⇒ Souffle::Provider::Base
Returns the current system provider.
-
#tag ⇒ String
The tag for the given node.
-
#to_hash ⇒ Hash
Returns the description of a node in hash format.
-
#try_opt(opt) ⇒ String
Tries to fetch an option parameter otherwise it grabs it from config.
-
#weight ⇒ Fixnum
The dependency weight of a given node.
Constructor Details
#initialize(parent_multiplier = 5) ⇒ Node
Creates a new souffle node with bare dependencies and run_list.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/souffle/node.rb', line 15 def initialize(parent_multiplier=5) @dependencies = Souffle::Node::RunList.new @run_list = Souffle::Node::RunList.new @parents = [] @children = [] @options = { :attributes => Hash.new } @parent_multiplier = parent_multiplier end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def children @children end |
#dependencies ⇒ Object
Returns the value of attribute dependencies.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def dependencies @dependencies end |
#name ⇒ Object
Returns the value of attribute name.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def @options end |
#parents ⇒ Object
Returns the value of attribute parents.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def parents @parents end |
#provisioner ⇒ Object
Returns the value of attribute provisioner.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def provisioner @provisioner end |
#run_list ⇒ Object
Returns the value of attribute run_list.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def run_list @run_list end |
#system ⇒ Object
Returns the value of attribute system.
9 10 11 |
# File 'lib/souffle/node.rb', line 9 def system @system end |
Instance Method Details
#add_child(node) ⇒ Object
Adds a child node to the current node.
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/souffle/node.rb', line 55 def add_child(node) unless node.respond_to?(:dependencies) && node.respond_to?(:run_list) raise Souffle::Exceptions::InvalidChild, "Child must act as a Souffle::Node" end unless @children.include? node node.parents << self @children.push(node) end end |
#depends_on?(node) ⇒ Array
Check whether or not a given node depends on another node.
42 43 44 45 46 47 48 |
# File 'lib/souffle/node.rb', line 42 def depends_on?(node) dependency_list = [] @dependencies.each do |d| dependency_list << d if node.run_list.include? d end [dependency_list.any?, dependency_list] end |
#domain ⇒ String
The top-level domain name for the given node.
126 127 128 |
# File 'lib/souffle/node.rb', line 126 def domain try_opt(:domain) end |
#each_child {|Souffle::Node, NilClass| ... } ⇒ Object
Iterator method for children.
69 70 71 |
# File 'lib/souffle/node.rb', line 69 def each_child @children.each { |child| yield child } end |
#eql?(other) ⇒ Boolean
Equality comparator for nodes.
76 77 78 |
# File 'lib/souffle/node.rb', line 76 def eql?(other) @dependencies == other.dependencies && @run_list == other.run_list end |
#fqdn ⇒ String
The fully qualified domain name for the given node.
133 134 135 |
# File 'lib/souffle/node.rb', line 133 def fqdn [name, tag, domain].compact.join('.') end |
#log_prefix ⇒ String
The logging prefix for the given node.
112 113 114 |
# File 'lib/souffle/node.rb', line 112 def log_prefix "[#{tag}: #{name}]" end |
#provider ⇒ Souffle::Provider::Base
Returns the current system provider.
105 106 107 |
# File 'lib/souffle/node.rb', line 105 def provider system.provider end |
#tag ⇒ String
The tag for the given node.
119 120 121 |
# File 'lib/souffle/node.rb', line 119 def tag try_opt(:tag) end |
#to_hash ⇒ Hash
Returns the description of a node in hash format.
140 141 142 143 144 145 146 147 148 |
# File 'lib/souffle/node.rb', line 140 def to_hash { :name => @name, :options => @options, :provisioner => @provisioner, :dependencies => @dependencies.to_hash, :run_list => @run_list.to_hash } end |
#try_opt(opt) ⇒ String
Tries to fetch an option parameter otherwise it grabs it from config.
92 93 94 95 96 97 98 99 100 |
# File 'lib/souffle/node.rb', line 92 def try_opt(opt) if system .fetch(opt, system.try_opt(opt)) else .fetch(opt, Souffle::Config[opt]) end rescue nil end |
#weight ⇒ Fixnum
The dependency weight of a given node.
83 84 85 |
# File 'lib/souffle/node.rb', line 83 def weight @parents.inject(1) { |res, p| res + p.weight * @parent_multiplier } end |