class Souffle::Node
A node object that's part of a given system.
A node object that's part of a given system.
Attributes
Public Class Methods
Creates a new souffle node with bare dependencies and run_list.
@param [ Fixnum ] parent_multiplier The multiplier for parent nodes.
# 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
Public Instance Methods
Adds a child node to the current node.
@param [ Souffle::Node
] node The node to add as a child.
@raise [ InvaidChild ] Children must have dependencies and a run_list.
# 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
Check whether or not a given node depends on another node.
@example
n1 = Souffle::Node.new n2 = Souffle::Node.new n1.run_list << "role[dns_server]" n2.dependencies << "role[dns_server]" n2.depends_on?(n1) > [ true, [role[dns_server]] ]
@param [ Souffle::Node
] node Check to see whether this node depends
@return [ Array ] The tuple of [depends_on, dependency_list].
# 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
The top-level domain name for the given node.
@return [ String ] The top-level domain name for the given node.
# File lib/souffle/node.rb, line 126 def domain try_opt(:domain) end
Iterator method for children.
@yield [ Souffle::Node
,NilClass ] The child node.
# File lib/souffle/node.rb, line 69 def each_child @children.each { |child| yield child } end
Equality comparator for nodes.
@param [ Souffle::Node
] other The node to compare against.
# File lib/souffle/node.rb, line 76 def eql?(other) @dependencies == other.dependencies && @run_list == other.run_list end
The fully qualified domain name for the given node.
@return [ String ] The fully qualified domain name for the given node.
# File lib/souffle/node.rb, line 133 def fqdn [name, tag, domain].compact.join('.') end
The logging prefix for the given node.
@return [ String ] The logging prefix for the given node.
# File lib/souffle/node.rb, line 112 def log_prefix "[#{tag}: #{name}]" end
Returns the current system provider.
@return [ Souffle::Provider::Base
] The current system provider.
# File lib/souffle/node.rb, line 105 def provider system.provider end
The tag for the given node.
@return [ String ] The tag for the given node.
# File lib/souffle/node.rb, line 119 def tag try_opt(:tag) end
Returns the description of a node in hash format.
@return [ Hash ] The description of a node in hash format.
# 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
Tries to fetch an option parameter otherwise it grabs it from config.
@param [ Symbol ] opt The option to try and fetch.
@return [ String ] The option return value.
# File lib/souffle/node.rb, line 92 def try_opt(opt) if system options.fetch(opt, system.try_opt(opt)) else options.fetch(opt, Souffle::Config[opt]) end rescue nil end
The dependency weight of a given node.
@return [ Fixnum ] The relative weight of a node used for balancing.
# File lib/souffle/node.rb, line 83 def weight @parents.inject(1) { |res, p| res + p.weight * @parent_multiplier } end