# class Puppet::Relationship

This is Puppet’s class for modeling edges in its configuration graph. It used to be a subclass of GRATR::Edge, but that class has weird hash overrides that dramatically slow down the graphing.

### Attributes

callback[RW]
event[R]
source[RW]
target[RW]

### Public Class Methods

from_pson(pson) click to toggle source

    # File lib/puppet/relationship.rb, line 17
    def self.from_pson(pson)
      source = pson["source"]
      target = pson["target"]

      args = {}
      if event = pson["event"]
        args[:event] = event
      end
      if callback = pson["callback"]
        args[:callback] = callback
      end

      new(source, target, args)
    end

new(source, target, options = {}) click to toggle source

    # File lib/puppet/relationship.rb, line 37
    def initialize(source, target, options = {})
      @source, @target = source, target

      options = (options || {}).inject({}) { |h,a| h[a[0].to_sym] = a[1]; h }
      [:callback, :event].each do |option|
        if value = options[option]
          send(option.to_s + "=", value)
        end
      end
    end

### Public Instance Methods

event=(event) click to toggle source

    # File lib/puppet/relationship.rb, line 32
    def event=(event)
      raise ArgumentError, "You must pass a callback for non-NONE events" if event != :NONE and ! callback
      @event = event
    end

inspect() click to toggle source

    # File lib/puppet/relationship.rb, line 71
    def inspect
      "{ #{source} => #{target} }"
    end

label() click to toggle source

    # File lib/puppet/relationship.rb, line 60
    def label
      result = {}
      result[:callback] = callback if callback
      result[:event] = event if event
      result
    end

match?(event) click to toggle source

Does the passed event match our event? This is where the meaning of :NONE comes from.

    # File lib/puppet/relationship.rb, line 50
    def match?(event)
      if self.event.nil? or event == :NONE or self.event == :NONE
        return false
      elsif self.event == :ALL_EVENTS or event == self.event
        return true
      else
        return false
      end
    end

ref() click to toggle source

    # File lib/puppet/relationship.rb, line 67
    def ref
      "#{source} => #{target}"
    end

to_pson(*args) click to toggle source

    # File lib/puppet/relationship.rb, line 88
    def to_pson(*args)
      to_pson_data_hash.to_pson(*args)
    end

to_pson_data_hash() click to toggle source

    # File lib/puppet/relationship.rb, line 75
    def to_pson_data_hash
      data = {
        'source' => source.to_s,
        'target' => target.to_s
      }

      ["event", "callback"].each do |attr|
        next unless value = send(attr)
        data[attr] = value
      end
      data
    end

to_s() click to toggle source

    # File lib/puppet/relationship.rb, line 92
    def to_s
      ref
    end