Class: Wonkavision::EventPathSegment

Inherits:
Object
  • Object
show all
Defined in:
lib/wonkavision/event_path_segment.rb

Direct Known Subclasses

Event, EventNamespace

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/wonkavision/event_path_segment.rb', line 3

def name
  @name
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/wonkavision/event_path_segment.rb', line 3

def namespace
  @namespace
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'lib/wonkavision/event_path_segment.rb', line 3

def options
  @options
end

#subscribersObject (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

#pathObject



12
13
14
# File 'lib/wonkavision/event_path_segment.rb', line 12

def path
  Wonkavision.join(namespace.blank? ? nil : namespace.path,name)
end

#root_namespaceObject



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