Class: Arborist::Event::NodeDelta

Inherits:
Node show all
Includes:
HashUtilities
Defined in:
lib/arborist/event/node_delta.rb

Overview

An event sent when one or more attributes of a node changes.

Instance Attribute Summary

Attributes inherited from Node

#node

Instance Method Summary collapse

Methods included from HashUtilities

compact_hash, hash_matches, merge_recursively, stringify_keys, symbolify_keys

Methods inherited from Node

#inspect_details, #to_h

Methods inherited from Arborist::Event

#inspect, #inspect_details, #to_h, #type

Constructor Details

#initialize(node, delta) ⇒ NodeDelta

Create a new NodeDelta event for the specified node. The delta is a Hash of:

attribute_name => [ old_value, new_value ]


17
18
19
# File 'lib/arborist/event/node_delta.rb', line 17

def initialize( node, delta )
	super # Overridden for the documentation
end

Instance Method Details

#delta_matches?(criteria, if_empty: true) ⇒ Boolean

Returns true if the ‘delta’ value of the specified criteria (which must respond to .all?) matches the delta this event represents. If the specified criteria doesn’t contain any ‘delta` criteria, the default value is used instead.

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/arborist/event/node_delta.rb', line 48

def delta_matches?( criteria, if_empty: true )
	self.log.debug "Delta matching %p (%p if empty)" % [ criteria, if_empty ]
	delta_criteria = criteria['delta']
	return if_empty if !delta_criteria || delta_criteria.empty?

	self.log.debug "Matching event against delta criteria: %p" % [ delta_criteria ]

	return delta_criteria.all? do |key, val|
		self.log.debug "  matching %p: %p against %p" % [ key, val, self.payload ]
		hash_matches( self.payload, key, val )
	end.tap {|match| self.log.debug "  event delta %s match." % [ match ? "DID" : "did not"] }
end

#informational?Boolean

Returns true if the event contains node information other than about a change in its state.

Returns:

  • (Boolean)


30
31
32
# File 'lib/arborist/event/node_delta.rb', line 30

def informational?
	return true
end

#match(object) ⇒ Object

Returns true if the specified object matches this event.



36
37
38
39
40
41
42
# File 'lib/arborist/event/node_delta.rb', line 36

def match( object )
	rval = super &&
		self.delta_matches?( object.criteria ) &&
		!self.delta_matches?( object.negative_criteria, if_empty: false )
	self.log.debug "Delta event #match: %p" % [ rval ]
	return rval
end

#payloadObject

Overridden so delta events only contain the diff of attributes that changed.



23
24
25
# File 'lib/arborist/event/node_delta.rb', line 23

def payload
	return @payload
end