Class: Wonkavision::EventPathSegment
- Inherits:
-
Object
- Object
- Wonkavision::EventPathSegment
- Defined in:
- lib/wonkavision/event_path_segment.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#namespace ⇒ Object
readonly
Returns the value of attribute namespace.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#subscribers ⇒ Object
readonly
Returns the value of attribute subscribers.
Instance Method Summary collapse
-
#initialize(name = nil, namespace = nil, opts = {}) ⇒ EventPathSegment
constructor
A new instance of EventPathSegment.
- #notify_subscribers(event_data, event_path = self.path) ⇒ Object
- #path ⇒ Object
- #root_namespace ⇒ Object
- #subscribe(&block) ⇒ Object
Constructor Details
#initialize(name = nil, namespace = nil, opts = {}) ⇒ EventPathSegment
Returns a new instance of EventPathSegment.
5 6 7 8 9 10 |
# File 'lib/wonkavision/event_path_segment.rb', line 5 def initialize(name = nil, namespace = nil, opts={}) @name = name @namespace = namespace @options = opts @subscribers = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/wonkavision/event_path_segment.rb', line 3 def name @name end |
#namespace ⇒ Object (readonly)
Returns the value of attribute namespace.
3 4 5 |
# File 'lib/wonkavision/event_path_segment.rb', line 3 def namespace @namespace end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/wonkavision/event_path_segment.rb', line 3 def @options end |
#subscribers ⇒ Object (readonly)
Returns the value of attribute subscribers.
3 4 5 |
# File 'lib/wonkavision/event_path_segment.rb', line 3 def subscribers @subscribers end |
Instance Method Details
#notify_subscribers(event_data, event_path = self.path) ⇒ Object
21 22 23 24 25 |
# File 'lib/wonkavision/event_path_segment.rb', line 21 def notify_subscribers(event_data, event_path=self.path) @subscribers.each do |sub| sub.call(event_data,event_path) end end |
#path ⇒ Object
12 13 14 |
# File 'lib/wonkavision/event_path_segment.rb', line 12 def path Wonkavision.join(namespace.blank? ? nil : namespace.path,name) end |
#root_namespace ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/wonkavision/event_path_segment.rb', line 27 def root_namespace cur_namespace = self while (cur_namespace.namespace) cur_namespace=cur_namespace.namespace end cur_namespace end |
#subscribe(&block) ⇒ Object
16 17 18 19 |
# File 'lib/wonkavision/event_path_segment.rb', line 16 def subscribe(&block) @subscribers << block self end |