# 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, line 1387
    def self.inherited(sub)
      @subclasses << sub
    end

### Public Instance Methods

munge(references) click to toggle source

@return [Array<Puppet::Resource>] turns attribute value(s) into list of resources

    # File lib/puppet/type.rb, line 1392
    def munge(references)
      references = [references] unless references.is_a?(Array)
      references.collect do |ref|
        if ref.is_a?(Puppet::Resource)
          ref
        else
          Puppet::Resource.new(ref)
        end
      end
    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, line 1429
    def to_edges
      @value.collect do |reference|
        reference.catalog = resource.catalog

        # Either of the two retrieval attempts could have returned
        # nil.
        unless related_resource = reference.resolve
          self.fail "Could not retrieve dependency '#{reference}' of #{@resource.ref}"
        end

        # Are we requiring them, or vice versa?  See the method docs
        # for futher info on this.
        if self.class.direction == :in
          source = related_resource
          target = @resource
        else
          source = @resource
          target = related_resource
        end

        if method = self.class.callback
          subargs = {
            :event => self.class.events,
            :callback => method
          }
          self.debug("subscribes to #{related_resource.ref}")
        else
          # If there's no callback, there's no point in even adding
          # a label.
          subargs = nil
          self.debug("requires #{related_resource.ref}")
        end

        rel = Puppet::Relationship.new(source, target, subargs)
      end
    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, line 1407
    def validate_relationship
      @value.each do |ref|
        unless @resource.catalog.resource(ref.to_s)
          description = self.class.direction == :in ? "dependency" : "dependent"
          fail "Could not find #{description} #{ref} for #{resource.ref}"
        end
      end
    end