Class: Arborist::NodeSubscription
- Inherits:
-
Subscription
- Object
- Subscription
- Arborist::NodeSubscription
- Defined in:
- lib/arborist/node_subscription.rb
Overview
An inter-node event subscription
Instance Attribute Summary collapse
-
#node ⇒ Object
readonly
The target node.
Attributes inherited from Subscription
#callback, #criteria, #event_type, #id, #negative_criteria
Instance Method Summary collapse
-
#check_callback ⇒ Object
Check the node to make sure it can handle published events.
-
#generate_id ⇒ Object
Return an ID derived from the node’s identifier.
-
#initialize(node) ⇒ NodeSubscription
constructor
Create a new subscription object that will send events to the given
node
. -
#inspect ⇒ Object
Return a String representation of the object suitable for debugging.
-
#node_identifier ⇒ Object
Return the identifier of the subscribed node.
-
#on_events(*events) ⇒ Object
Publish any of the specified
events
which match the subscription.
Methods inherited from Subscription
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
#node ⇒ Object (readonly)
The target node
25 26 27 |
# File 'lib/arborist/node_subscription.rb', line 25 def node @node end |
Instance Method Details
#check_callback ⇒ Object
Check the node to make sure it can handle published events.
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_id ⇒ Object
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 |
#inspect ⇒ Object
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_identifier ⇒ Object
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 |