# class Puppet::Util::Instrumentation::Listener

### Attributes

enabled[RW]
listener[R]
pattern[R]

### Public Class Methods

from_pson(data) click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 56
    def self.from_pson(data)
      result = Puppet::Util::Instrumentation[data["name"]]
      self.new(result.listener, result.pattern, data["enabled"])
    end

new(listener, pattern = nil, enabled = false) click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 15
    def initialize(listener, pattern = nil, enabled = false)
      @pattern = pattern.is_a?(Symbol) ? pattern.to_s : pattern
      raise "Listener isn't a correct listener (it doesn't provide the notify method)" unless listener.respond_to?(:notify)
      @listener = listener
      @enabled = enabled
    end

### Public Instance Methods

data() click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 40
    def data
      { :data => @listener.data }
    end

enabled?() click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 32
    def enabled?
      !!@enabled
    end

listen_to?(label) click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 28
    def listen_to?(label)
      enabled? and (!@pattern || @pattern === label.to_s)
    end

name() click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 36
    def name
      @listener.name.to_s
    end

notify(label, event, data) click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 22
    def notify(label, event, data)
      listener.notify(label, event, data)
    rescue => e
      warnonce("Error during instrumentation notification: #{e}")
    end

to_pson(*args) click to toggle source

    # File lib/puppet/util/instrumentation/listener.rb, line 44
    def to_pson(*args)
      result = {
        :document_type => "Puppet::Util::Instrumentation::Listener",
        :data => {
          :name => name,
          :pattern => pattern,
          :enabled => enabled?
        }
      }
      result.to_pson(*args)
    end