Class: Puppet::Relationship
- Includes:
- Network::FormatSupport, Util::PsychSupport
- 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
-
#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_data_hash ⇒ Object
- #to_s ⇒ Object
Methods included from Util::PsychSupport
Methods included from Network::FormatSupport
included, #mime, #render, #support_format?, #to_json, #to_msgpack, #to_pson
Constructor Details
#initialize(source, target, options = {}) ⇒ Relationship
Returns a new instance of Relationship.
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/puppet/relationship.rb', line 36 def initialize(source, target, = {}) @source = source @target = target = ( || {}).each_with_object({}) { |a, h| h[a[0].to_sym] = a[1]; } [:callback, :event].each do |option| value = [option] send(option.to_s + "=", value) if value end end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
14 15 16 |
# File 'lib/puppet/relationship.rb', line 14 def callback @callback end |
#event ⇒ Object
Returns the value of attribute event.
16 17 18 |
# File 'lib/puppet/relationship.rb', line 16 def event @event end |
#source ⇒ Object
Returns the value of attribute source.
14 15 16 |
# File 'lib/puppet/relationship.rb', line 14 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
14 15 16 |
# File 'lib/puppet/relationship.rb', line 14 def target @target end |
Class Method Details
.from_data_hash(data) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/puppet/relationship.rb', line 18 def self.from_data_hash(data) source = data['source'] target = data['target'] args = {} args[:event] = :"#{data['event']}" if data["event"] args[:callback] = :"#{data['callback']}" if data["callback"] new(source, target, args) end |
Instance Method Details
#inspect ⇒ Object
68 69 70 |
# File 'lib/puppet/relationship.rb', line 68 def inspect "{ #{source} => #{target} }" end |
#label ⇒ Object
57 58 59 60 61 62 |
# File 'lib/puppet/relationship.rb', line 57 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.
49 50 51 52 53 54 55 |
# File 'lib/puppet/relationship.rb', line 49 def match?(event) if self.event.nil? or event == :NONE or self.event == :NONE false else self.event == :ALL_EVENTS or event == self.event end end |
#ref ⇒ Object
64 65 66 |
# File 'lib/puppet/relationship.rb', line 64 def ref "#{source} => #{target}" end |
#to_data_hash ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/puppet/relationship.rb', line 72 def to_data_hash data = { 'source' => source.to_s, 'target' => target.to_s } data['event'] = event.to_s unless event.nil? data['callback'] = callback.to_s unless callback.nil? data end |
#to_s ⇒ Object
82 83 84 |
# File 'lib/puppet/relationship.rb', line 82 def to_s ref end |