Class: Puppet::Parser::Relationship
- Defined in:
- lib/puppet/parser/relationship.rb
Constant Summary collapse
- PARAM_MAP =
{ :relationship => :before, :subscription => :notify }
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #arrayify(resources, left) ⇒ Object
- #evaluate(catalog) ⇒ Object
-
#initialize(source, target, type) ⇒ Relationship
constructor
A new instance of Relationship.
- #mk_relationship(source, target, catalog) ⇒ Object
- #param_name ⇒ Object
Constructor Details
#initialize(source, target, type) ⇒ Relationship
Returns a new instance of Relationship.
28 29 30 31 32 |
# File 'lib/puppet/parser/relationship.rb', line 28 def initialize(source, target, type) @source = source @target = target @type = type end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
4 5 6 |
# File 'lib/puppet/parser/relationship.rb', line 4 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
4 5 6 |
# File 'lib/puppet/parser/relationship.rb', line 4 def target @target end |
#type ⇒ Object
Returns the value of attribute type.
4 5 6 |
# File 'lib/puppet/parser/relationship.rb', line 4 def type @type end |
Instance Method Details
#arrayify(resources, left) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/puppet/parser/relationship.rb', line 8 def arrayify(resources, left) case resources when Puppet::Pops::Evaluator::Collectors::AbstractCollector # on the LHS, go as far left as possible, else whatever the collected result is left ? leftmost_alternative(resources) : resources.collected.values when Array resources else [resources] end end |
#evaluate(catalog) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/puppet/parser/relationship.rb', line 20 def evaluate(catalog) arrayify(source, true).each do |s| arrayify(target, false).each do |t| mk_relationship(s, t, catalog) end end end |
#mk_relationship(source, target, catalog) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/puppet/parser/relationship.rb', line 38 def mk_relationship(source, target, catalog) source_ref = canonical_ref(source) target_ref = canonical_ref(target) rel_param = param_name source_resource = catalog.resource(*source_ref) unless source_resource raise ArgumentError, _("Could not find resource '%{source}' for relationship on '%{target}'") % { source: source.to_s, target: target.to_s } end unless catalog.resource(*target_ref) raise ArgumentError, _("Could not find resource '%{target}' for relationship from '%{source}'") % { target: target.to_s, source: source.to_s } end Puppet.debug { "Adding relationship from #{source} to #{target} with '#{param_name}'" } if source_resource[rel_param].class != Array source_resource[rel_param] = [source_resource[rel_param]].compact end source_resource[rel_param] << (target_ref[1].nil? ? target_ref[0] : "#{target_ref[0]}[#{target_ref[1]}]") end |