Class: Puppet::Relationship
- 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
-
#initialize(source, target, options = {}) ⇒ Relationship
constructor
A new instance of Relationship.
- #inspect ⇒ Object
- #label ⇒ Object
-
#match?(event) ⇒ Boolean
Does the passed event match our event? This is where the meaning of :NONE comes from.
- #ref ⇒ Object
- #to_data_hash ⇒ Object
- #to_pson(*args) ⇒ Object
-
#to_pson_data_hash ⇒ Object
This doesn’t include document type as it is part of a catalog.
- #to_s ⇒ Object
Methods included from Util::Pson
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, = {}) @source, @target = source, target = ( || {}).inject({}) { |h,a| h[a[0].to_sym] = a[1]; h } [:callback, :event].each do |option| if value = [option] send(option.to_s + "=", value) end end end |
Instance Attribute Details
Class Method Details
.from_data_hash(data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/puppet/relationship.rb', line 15 def self.from_data_hash(data) source = data["source"] target = data["target"] args = {} if event = data["event"] args[:event] = event end if callback = data["callback"] args[:callback] = callback end new(source, target, args) end |
.from_pson(pson) ⇒ Object
30 31 32 33 |
# File 'lib/puppet/relationship.rb', line 30 def self.from_pson(pson) Puppet.deprecation_warning("from_pson is being removed in favour of from_data_hash.") self.from_data_hash(pson) end |
Instance Method Details
#inspect ⇒ Object
74 75 76 |
# File 'lib/puppet/relationship.rb', line 74 def inspect "{ #{source} => #{target} }" end |
#label ⇒ Object
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.
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 |
#ref ⇒ Object
70 71 72 |
# File 'lib/puppet/relationship.rb', line 70 def ref "#{source} => #{target}" end |
#to_data_hash ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/puppet/relationship.rb', line 78 def to_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_pson(*args) ⇒ Object
96 97 98 |
# File 'lib/puppet/relationship.rb', line 96 def to_pson(*args) to_data_hash.to_pson(*args) end |
#to_pson_data_hash ⇒ Object
This doesn’t include document type as it is part of a catalog
92 93 94 |
# File 'lib/puppet/relationship.rb', line 92 def to_pson_data_hash to_data_hash end |