Sha256: a531a38191d688f76878c662151ed367778056700c651466456a2eb2f5eea6ac

Contents?: true

Size: 1.96 KB

Versions: 164

Compression:

Stored size: 1.96 KB

Contents

# subscriptions are permanent associations determining how different
# objects react to an event

# 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.
class Puppet::Relationship

  # FormatSupport for serialization methods
  include Puppet::Network::FormatSupport

  attr_accessor :source, :target, :callback

  attr_reader :event

  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

  def event=(event)
    raise ArgumentError, "You must pass a callback for non-NONE events" if event != :NONE and ! callback
    @event = event
  end

  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

  # Does the passed event match our event?  This is where the meaning
  # of :NONE comes from.
  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

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

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

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

  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

  def to_s
    ref
  end
end

Version data entries

164 entries across 164 versions & 2 rubygems

Version Path
puppet-retrospec-1.8.0 vendor/pup410/lib/puppet/relationship.rb
puppet-retrospec-1.7.0 vendor/pup410/lib/puppet/relationship.rb
puppet-4.10.12 lib/puppet/relationship.rb
puppet-4.10.12-x86-mingw32 lib/puppet/relationship.rb
puppet-4.10.12-x64-mingw32 lib/puppet/relationship.rb
puppet-4.10.12-universal-darwin lib/puppet/relationship.rb
puppet-4.10.11 lib/puppet/relationship.rb
puppet-4.10.11-x86-mingw32 lib/puppet/relationship.rb
puppet-4.10.11-x64-mingw32 lib/puppet/relationship.rb
puppet-4.10.11-universal-darwin lib/puppet/relationship.rb
puppet-4.10.10 lib/puppet/relationship.rb
puppet-4.10.10-x86-mingw32 lib/puppet/relationship.rb
puppet-4.10.10-x64-mingw32 lib/puppet/relationship.rb
puppet-4.10.10-universal-darwin lib/puppet/relationship.rb
puppet-retrospec-1.6.1 vendor/pup410/lib/puppet/relationship.rb
puppet-retrospec-1.6.0 vendor/pup410/lib/puppet/relationship.rb
puppet-4.10.9 lib/puppet/relationship.rb
puppet-4.10.9-x86-mingw32 lib/puppet/relationship.rb
puppet-4.10.9-x64-mingw32 lib/puppet/relationship.rb
puppet-4.10.9-universal-darwin lib/puppet/relationship.rb