Class: Evnt::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/evnt/handler.rb

Overview

Handlers are used to listen one or more events and run tasks after their execution.

Direct Known Subclasses

ApplicationHandler

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#eventObject (readonly)

Attribute containings the event that notify the handler.



13
14
15
# File 'lib/evnt/handler.rb', line 13

def event
  @event
end

Class Method Details

.listen(event) ⇒ Object

This function permits handler to listen specific event.



77
78
79
# File 'lib/evnt/handler.rb', line 77

def listen(event)
  event.add_handler(new)
end

.on(event_name, &block) ⇒ Object

This function sets the blocks executed for a specific event.



82
83
84
85
# File 'lib/evnt/handler.rb', line 82

def on(event_name, &block)
  @_current_event_name = event_name
  block.yield
end

.to_manage_event(&block) ⇒ Object

This function sets the manage event function for the event.



93
94
95
# File 'lib/evnt/handler.rb', line 93

def to_manage_event(&block)
  define_method("#{@_current_event_name}_manage_event", &block)
end

.to_manage_reloaded_event(&block) ⇒ Object

This function sets the manage reloaded event function for the event.



98
99
100
# File 'lib/evnt/handler.rb', line 98

def to_manage_reloaded_event(&block)
  define_method("#{@_current_event_name}_manage_reloaded_event", &block)
end

.to_update_queries(&block) ⇒ Object

This function sets the update queries function for the event.



88
89
90
# File 'lib/evnt/handler.rb', line 88

def to_update_queries(&block)
  define_method("#{@_current_event_name}_update_queries", &block)
end

Instance Method Details

#notify(event) ⇒ Object

This function is called from an event to notify an handler.

Attributes

  • event - The event object that call the function.



22
23
24
25
# File 'lib/evnt/handler.rb', line 22

def notify(event)
  _init_handler_data(event)
  _run_handler_steps
end