Class: Arborist::Event::Node

Inherits:
Arborist::Event show all
Defined in:
lib/arborist/event/node.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Arborist::Event

#informational?, #inspect, #type

Constructor Details

#initialize(node, payload = nil) ⇒ Node

Strip and save the node argument to the constructor.



11
12
13
14
# File 'lib/arborist/event/node.rb', line 11

def initialize( node, payload=nil )
	@node = node
	super( payload )
end

Instance Attribute Details

#nodeObject (readonly)

The node that generated the event



22
23
24
# File 'lib/arborist/event/node.rb', line 22

def node
  @node
end

Instance Method Details

#inspect_detailsObject

Return the detail portion of the #inspect string appropriate for this event type.



42
43
44
45
46
47
48
# File 'lib/arborist/event/node.rb', line 42

def inspect_details
	return "%s(%s)%s" % [
		self.node.identifier,
		self.node.type,
		self.node.flapping? ? ' (flapping)' : '',
	]
end

#match(object) ⇒ Object

Returns true if the specified object matches this event.



26
27
28
29
30
31
32
# File 'lib/arborist/event/node.rb', line 26

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

#payloadObject

Use the node data as this event’s payload.



36
37
38
# File 'lib/arborist/event/node.rb', line 36

def payload
	return self.node.to_h
end

#to_hObject

Inject useful node metadata into the generated hash.



52
53
54
55
56
57
58
59
# File 'lib/arborist/event/node.rb', line 52

def to_h
	return super.merge(
		identifier:  self.node.identifier,
		parent:      self.node.parent,
		nodetype:    self.node.type,
		flapping:    self.node.flapping?
	)
end