Class: Arborist::NodeSubscription

Inherits:
Subscription show all
Defined in:
lib/arborist/node_subscription.rb

Overview

An inter-node event subscription

Instance Attribute Summary collapse

Attributes inherited from Subscription

#callback, #criteria, #event_type, #id, #negative_criteria

Instance Method Summary collapse

Methods inherited from Subscription

#exclude, #interested_in?

Methods included from HashUtilities

compact_hash, hash_matches, merge_recursively, stringify_keys, symbolify_keys

Constructor Details

#initialize(node) ⇒ NodeSubscription

Create a new subscription object that will send events to the given node.



13
14
15
16
# File 'lib/arborist/node_subscription.rb', line 13

def initialize( node )
	@node = node
	super()
end

Instance Attribute Details

#nodeObject (readonly)

The target node



25
26
27
# File 'lib/arborist/node_subscription.rb', line 25

def node
  @node
end

Instance Method Details

#check_callbackObject

Check the node to make sure it can handle published events.

Raises:

  • (NameError)


41
42
43
44
# File 'lib/arborist/node_subscription.rb', line 41

def check_callback
	raise NameError, "node doesn't implement handle_event" unless
		self.node.respond_to?( :handle_event )
end

#generate_idObject

Return an ID derived from the node’s identifier.



35
36
37
# File 'lib/arborist/node_subscription.rb', line 35

def generate_id
	return "%s-subscription" % [ self.node_identifier ]
end

#inspectObject

Return a String representation of the object suitable for debugging.



56
57
58
59
60
61
62
# File 'lib/arborist/node_subscription.rb', line 56

def inspect
	return "#<%p:%#x for the %s node>" % [
		self.class,
		self.object_id * 2,
		self.node.identifier,
	]
end

#node_identifierObject

Return the identifier of the subscribed node.



29
30
31
# File 'lib/arborist/node_subscription.rb', line 29

def node_identifier
	return self.node.identifier
end

#on_events(*events) ⇒ Object

Publish any of the specified events which match the subscription.



48
49
50
51
52
# File 'lib/arborist/node_subscription.rb', line 48

def on_events( *events )
	events.flatten.each do |event|
		self.node.handle_event( event )
	end
end