Sha256: 5dd613d7af1422ab69efda3d22554a38ebe88ac86928f2e6c38789e54b13ab1f

Contents?: true

Size: 1.29 KB

Versions: 2

Compression:

Stored size: 1.29 KB

Contents

# -*- ruby -*-
#encoding: utf-8

require 'arborist/event' unless defined?( Arborist::Event )


# A base class for events which are related to an Arborist::Node.
class Arborist::Event::Node < Arborist::Event

	### Strip and save the node argument to the constructor.
	def initialize( node, payload=nil )
		@node = node
		super( payload )
	end


	######
	public
	######

	# The node that generated the event
	attr_reader :node


	### Returns +true+ if the specified +object+ matches this event.
	def match( object )
		rval = super &&
			self.node.matches?( object.criteria ) &&
			!self.node.matches?( object.negative_criteria, if_empty: false )
		self.log.debug "Node event #match: %p" % [ rval ]
		return rval
	end


	### Use the node data as this event's payload.
	def payload
		return self.node.to_h
	end


	### Return the detail portion of the #inspect string appropriate for this event type.
	def inspect_details
		return "%s(%s)%s" % [
			self.node.identifier,
			self.node.type,
			self.node.flapping? ? ' (flapping)' : '',
		]
	end


	### Inject useful node metadata into the generated hash.
	def to_h
		return super.merge(
			identifier:  self.node.identifier,
			parent:      self.node.parent,
			nodetype:    self.node.type,
			flapping:    self.node.flapping?
		)
	end

end # module Arborist::Event::NodeMatching

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
arborist-0.6.0 lib/arborist/event/node.rb
arborist-0.5.0 lib/arborist/event/node.rb