Class: Wonkavision::Event

Inherits:
EventPathSegment show all
Defined in:
lib/wonkavision/event.rb

Instance Attribute Summary

Attributes inherited from EventPathSegment

#name, #namespace, #options, #subscribers

Instance Method Summary collapse

Methods inherited from EventPathSegment

#path, #root_namespace, #subscribe

Constructor Details

#initialize(name, namespace, opts = {}) ⇒ Event

Returns a new instance of Event.



5
6
7
8
9
# File 'lib/wonkavision/event.rb', line 5

def initialize(name, namespace, opts={})
  super name,namespace,opts
  @source_events = []
  source_events(*opts.delete(:source_events)) if opts.keys.include?(:source_events)
end

Instance Method Details

#matches(event_path) ⇒ Object



11
12
13
# File 'lib/wonkavision/event.rb', line 11

def matches(event_path)
  event_path == path || @source_events.detect{|evt|evt.matches(event_path)} != nil
end

#notify_subscribers(event_data, event_path) ⇒ Object



15
16
17
# File 'lib/wonkavision/event.rb', line 15

def notify_subscribers(event_data,event_path)
  super(event_data,self.path)
end

#source_events(*args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/wonkavision/event.rb', line 19

def source_events(*args)
  return @source_events if args.blank?
  @source_events = @source_events.concat(args.map do |source|
     source_ns = namespace
     if (source=~/^\/.*/)
       source_ns = root_namespace
       source = source[1..-1]
     end
     source_ns.find_or_create(source)
  end)
end