Class: Puppet::Parser::Relationship
- Defined in:
- lib/puppet/parser/relationship.rb
Constant Summary collapse
- PARAM_MAP =
{:relationship => :before, :subscription => :notify}
Instance Attribute Summary collapse
Instance Method Summary collapse
- #arrayify(resources) ⇒ 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.
40 41 42 |
# File 'lib/puppet/parser/relationship.rb', line 40 def initialize(source, target, type) @source, @target, @type = source, target, type end |
Instance Attribute Details
Instance Method Details
#arrayify(resources) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/puppet/parser/relationship.rb', line 6 def arrayify(resources) # This if statement is needed because the 3x parser cannot load # Puppet::Pops. This logic can be removed for 4.0 when the 3x AST # is removed (when Pops is always used). if !(Puppet.future_parser?) case resources when Puppet::Parser::Collector resources.collected.values when Array resources else [resources] end else require 'puppet/pops' case resources when Puppet::Pops::Evaluator::Collectors::AbstractCollector resources.collected.values when Array resources else [resources] end end end |
#evaluate(catalog) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/puppet/parser/relationship.rb', line 32 def evaluate(catalog) arrayify(source).each do |s| arrayify(target).each do |t| mk_relationship(s, t, catalog) end end end |
#mk_relationship(source, target, catalog) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/puppet/parser/relationship.rb', line 48 def mk_relationship(source, target, catalog) # REVISIT: In Ruby 1.8 we applied `to_s` to source and target, rather than # `join` without an argument. In 1.9 the behaviour of Array#to_s changed, # and it gives a different representation than just concat the stringified # elements. # # This restores the behaviour, but doesn't address the underlying question # of what would happen when more than one item was passed in that array. # (Hint: this will not end well.) # # See http://projects.puppetlabs.com/issues/12076 for the ticket tracking # the fact that we should dig out the sane version of this behaviour, then # implement it - where we don't risk breaking a stable release series. # --daniel 2012-01-21 source = source.is_a?(Array) ? source.join : source.to_s target = target.is_a?(Array) ? target.join : target.to_s unless source_resource = catalog.resource(source) raise ArgumentError, "Could not find resource '#{source}' for relationship on '#{target}'" end unless catalog.resource(target) raise ArgumentError, "Could not find resource '#{target}' for relationship from '#{source}'" end Puppet.debug "Adding relationship from #{source} to #{target} with '#{param_name}'" if source_resource[param_name].class != Array source_resource[param_name] = [source_resource[param_name]].compact end source_resource[param_name] << target end |