class Puppet::Type::RelationshipMetaparam

RelationshipMetaparam is an implementation supporting the meta-parameters `:require`, `:subscribe`, `:notify`, and `:before`.

Attributes

callback[RW]
direction[RW]
events[RW]
subclasses[RW]

Public Class Methods

inherited(sub) click to toggle source
     # File lib/puppet/type.rb
1500 def self.inherited(sub)
1501   @subclasses << sub
1502 end

Public Instance Methods

munge(references) click to toggle source

@return [Array<Puppet::Resource>] turns attribute values into list of resources

     # File lib/puppet/type.rb
1505 def munge(references)
1506   references = [references] unless references.is_a?(Array)
1507   references.collect do |ref|
1508     if ref.is_a?(Puppet::Resource)
1509       ref
1510     else
1511       Puppet::Resource.new(ref)
1512     end
1513   end
1514 end
to_edges() click to toggle source

Creates edges for all relationships. The `:in` relationships are specified by the event-receivers, and `:out` relationships are specified by the event generator. @todo references to “event-receivers” and “event generator” means in this context - are those just

the resources at the two ends of the relationship?

This way 'source' and 'target' are consistent terms in both edges and events, i.e. an event targets edges whose source matches the event's source. The direction of the relationship determines which resource is applied first and which resource is considered to be the event generator. @return [Array<Puppet::Relationship>] @raise [???fail] when a reference can not be resolved

     # File lib/puppet/type.rb
1543 def to_edges
1544   @value.collect do |reference|
1545     reference.catalog = resource.catalog
1546 
1547     # Either of the two retrieval attempts could have returned
1548     # nil.
1549     related_resource = reference.resolve
1550     unless related_resource
1551       self.fail "Could not retrieve dependency '#{reference}' of #{@resource.ref}"
1552     end
1553 
1554     # Are we requiring them, or vice versa?  See the method docs
1555     # for further info on this.
1556     if self.class.direction == :in
1557       source = related_resource
1558       target = @resource
1559     else
1560       source = @resource
1561       target = related_resource
1562     end
1563 
1564     method = self.class.callback
1565     if method
1566       subargs = {
1567         :event => self.class.events,
1568         :callback => method
1569       }
1570     else
1571       # If there's no callback, there's no point in even adding
1572       # a label.
1573       subargs = nil
1574     end
1575 
1576     ## Corrected syntax of debug statement to reflect the way this was called.
1577     # i.e. before, after, subscribe, notify
1578     self.debug do
1579       relation = case self.class.name
1580       when "subscribe"
1581         "subscribes"
1582       when "notify"
1583         "notifies"
1584       else
1585         self.class.name
1586       end
1587 
1588       "#{relation} to #{related_resource.ref}"
1589     end
1590 
1591     Puppet::Relationship.new(source, target, subargs)
1592   end
1593 end
validate_relationship() click to toggle source

Checks each reference to assert that what it references exists in the catalog.

@raise [???fail] if the referenced resource can not be found @return [void]

     # File lib/puppet/type.rb
1520 def validate_relationship
1521   @value.each do |ref|
1522     unless @resource.catalog.resource(ref.to_s)
1523       description = self.class.direction == :in ? "dependency" : "dependent"
1524       fail ResourceError, _("Could not find %{description} %{ref} for %{resource}") %
1525           { description: description, ref: ref, resource: resource.ref }
1526     end
1527   end
1528 end