Class: Puppet::Relationship

Inherits:
Object show all
Extended by:
Util::Pson
Defined in:
lib/puppet/relationship.rb

Overview

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.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Util::Pson

pson_create

Constructor Details

#initialize(source, target, options = {}) ⇒ Relationship

Returns a new instance of Relationship.



40
41
42
43
44
45
46
47
48
49
# File 'lib/puppet/relationship.rb', line 40

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

Instance Attribute Details

#callbackObject

Returns the value of attribute callback.



16
17
18
# File 'lib/puppet/relationship.rb', line 16

def callback
  @callback
end

#eventObject

Returns the value of attribute event.



18
19
20
# File 'lib/puppet/relationship.rb', line 18

def event
  @event
end

#sourceObject

Returns the value of attribute source.



16
17
18
# File 'lib/puppet/relationship.rb', line 16

def source
  @source
end

#targetObject

Returns the value of attribute target.



16
17
18
# File 'lib/puppet/relationship.rb', line 16

def target
  @target
end

Class Method Details

.from_pson(pson) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/puppet/relationship.rb', line 20

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

Instance Method Details

#inspectObject



74
75
76
# File 'lib/puppet/relationship.rb', line 74

def inspect
  "{ #{source} => #{target} }"
end

#labelObject



63
64
65
66
67
68
# File 'lib/puppet/relationship.rb', line 63

def label
  result = {}
  result[:callback] = callback if callback
  result[:event] = event if event
  result
end

#match?(event) ⇒ Boolean

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

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
61
# File 'lib/puppet/relationship.rb', line 53

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

#refObject



70
71
72
# File 'lib/puppet/relationship.rb', line 70

def ref
  "#{source} => #{target}"
end

#to_pson(*args) ⇒ Object



91
92
93
# File 'lib/puppet/relationship.rb', line 91

def to_pson(*args)
  to_pson_data_hash.to_pson(*args)
end

#to_pson_data_hashObject



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/puppet/relationship.rb', line 78

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_sObject



95
96
97
# File 'lib/puppet/relationship.rb', line 95

def to_s
  ref
end