Class: Puppet::Relationship
- Extended by:
- Util::Pson
- Defined in:
- lib/vendor/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
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#event ⇒ Object
Returns the value of attribute event.
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
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_pson(*args) ⇒ Object
- #to_pson_data_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Util::Pson
Constructor Details
#initialize(source, target, options = {}) ⇒ Relationship
Returns a new instance of Relationship.
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/vendor/puppet/relationship.rb', line 37 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
#callback ⇒ Object
Returns the value of attribute callback.
13 14 15 |
# File 'lib/vendor/puppet/relationship.rb', line 13 def callback @callback end |
#event ⇒ Object
Returns the value of attribute event.
15 16 17 |
# File 'lib/vendor/puppet/relationship.rb', line 15 def event @event end |
#source ⇒ Object
Returns the value of attribute source.
13 14 15 |
# File 'lib/vendor/puppet/relationship.rb', line 13 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
13 14 15 |
# File 'lib/vendor/puppet/relationship.rb', line 13 def target @target end |
Class Method Details
.from_pson(pson) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/vendor/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 |
Instance Method Details
#inspect ⇒ Object
71 72 73 |
# File 'lib/vendor/puppet/relationship.rb', line 71 def inspect "{ #{source} => #{target} }" end |
#label ⇒ Object
60 61 62 63 64 65 |
# File 'lib/vendor/puppet/relationship.rb', line 60 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.
50 51 52 53 54 55 56 57 58 |
# File 'lib/vendor/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 ⇒ Object
67 68 69 |
# File 'lib/vendor/puppet/relationship.rb', line 67 def ref "#{source} => #{target}" end |
#to_pson(*args) ⇒ Object
88 89 90 |
# File 'lib/vendor/puppet/relationship.rb', line 88 def to_pson(*args) to_pson_data_hash.to_pson(*args) end |
#to_pson_data_hash ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/vendor/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 ⇒ Object
92 93 94 |
# File 'lib/vendor/puppet/relationship.rb', line 92 def to_s ref end |