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_data_hash(data) click to toggle source
   # File lib/puppet/relationship.rb
17 def self.from_data_hash(data)
18   source = data['source']
19   target = data['target']
20 
21   args = {}
22   args[:event] = :"#{data['event']}" if data["event"]
23   args[:callback] = :"#{data['callback']}" if data["callback"]
24 
25   new(source, target, args)
26 end
new(source, target, options = {}) click to toggle source
   # File lib/puppet/relationship.rb
34 def initialize(source, target, options = {})
35   @source, @target = source, target
36 
37   options = (options || {}).inject({}) { |h,a| h[a[0].to_sym] = a[1]; h }
38   [:callback, :event].each do |option|
39     value = options[option]
40     send(option.to_s + "=", value) if value
41   end
42 end

Public Instance Methods

event=(event) click to toggle source
   # File lib/puppet/relationship.rb
28 def event=(event)
29   #TRANSLATORS 'NONE' should not be translated
30   raise ArgumentError, _("You must pass a callback for non-NONE events") if event != :NONE and ! callback
31   @event = event
32 end
inspect() click to toggle source
   # File lib/puppet/relationship.rb
67 def inspect
68   "{ #{source} => #{target} }"
69 end
label() click to toggle source
   # File lib/puppet/relationship.rb
56 def label
57   result = {}
58   result[:callback] = callback if callback
59   result[:event] = event if event
60   result
61 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
46 def match?(event)
47   if self.event.nil? or event == :NONE or self.event == :NONE
48     return false
49   elsif self.event == :ALL_EVENTS or event == self.event
50     return true
51   else
52     return false
53   end
54 end
ref() click to toggle source
   # File lib/puppet/relationship.rb
63 def ref
64   "#{source} => #{target}"
65 end
to_data_hash() click to toggle source
   # File lib/puppet/relationship.rb
71 def to_data_hash
72   data = {
73     'source' => source.to_s,
74     'target' => target.to_s
75   }
76   data['event'] = event.to_s unless event.nil?
77   data['callback'] = callback.to_s unless callback.nil?
78   data
79 end
to_s() click to toggle source
   # File lib/puppet/relationship.rb
81 def to_s
82   ref
83 end