An inter-node event subscription
The target node
Create a new subscription object that will send events to the given
node
.
# File lib/arborist/node_subscription.rb, line 12
def initialize( node )
@node = node
super()
end
Check the node to make sure it can handle published events.
# File lib/arborist/node_subscription.rb, line 40
def check_callback
raise NameError, "node doesn't implement handle_event" unless
self.node.respond_to?( :handle_event )
end
Return an ID derived from the node's identifier.
# File lib/arborist/node_subscription.rb, line 34
def generate_id
return "%s-subscription" % [ self.node_identifier ]
end
Return a String representation of the object suitable for debugging.
# File lib/arborist/node_subscription.rb, line 55
def inspect
return "#<%p:%#x for the %s node>" % [
self.class,
self.object_id * 2,
self.node.identifier,
]
end
Return the identifier of the subscribed node.
# File lib/arborist/node_subscription.rb, line 28
def node_identifier
return self.node.identifier
end
Publish any of the specified events
which match the
subscription.
# File lib/arborist/node_subscription.rb, line 47
def on_events( *events )
events.flatten.each do |event|
self.node.handle_event( event )
end
end