Module: Wonkavision::Plugins::EventHandling::ClassMethods

Defined in:
lib/wonkavision/plugins/event_handling.rb

Instance Method Summary collapse

Instance Method Details

#create_binding(name, handler, *args) ⇒ Object



53
54
55
# File 'lib/wonkavision/plugins/event_handling.rb', line 53

def create_binding(name,handler,*args)
  Wonkavision::EventBinding.new(name,handler,*args)
end

#event_namespace(namespace = nil) ⇒ Object Also known as: namespace



27
28
29
30
# File 'lib/wonkavision/plugins/event_handling.rb', line 27

def event_namespace(namespace=nil)
  return event_handler_options[:event_namespace] unless namespace
  event_handler_options[:event_namespace] = namespace
end

#event_path(event_name) ⇒ Object



22
23
24
25
# File 'lib/wonkavision/plugins/event_handling.rb', line 22

def event_path(event_name)
  return event_name.to_s if Wonkavision.is_absolute_path(event_name) #don't mess with an absolute path
  Wonkavision.join(event_namespace,event_name)
end

#handle(name, *args, &block) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wonkavision/plugins/event_handling.rb', line 37

def handle(name,*args,&block)
  binding = create_binding(name,self,*args)
  binding.subscribe_to_events do |event_data,event_path|
    ctx = Wonkavision::EventContext.new(event_data,event_path,binding,block)
    handler = instantiate_handler(ctx)
    handler.instance_variable_set(:@wonkavision_event_context, ctx)
    handler.handle_event
  end
  bindings << binding
  binding
end

#instantiate_handler(event_context) ⇒ Object



49
50
51
# File 'lib/wonkavision/plugins/event_handling.rb', line 49

def instantiate_handler(event_context)
  self.new
end

#map(condition = nil, &block) ⇒ Object



33
34
35
# File 'lib/wonkavision/plugins/event_handling.rb', line 33

def map(condition = nil,&block)
  maps << [condition,block]
end

#optionsObject



18
19
20
# File 'lib/wonkavision/plugins/event_handling.rb', line 18

def options
  event_handler_options
end