Module: Vigilem::Core::EventHandler::ClassMethods
- Includes:
- Utils
- Defined in:
- lib/vigilem/core/event_handler.rb
Instance Method Summary collapse
-
#default_handler(&block) ⇒ Proc
sets the default_handler, if called without a block, just assigns the default handler to a “default”.
-
#on(type, opts = {}, &block) ⇒ Proc
(also: #register_handle)
configures how this event handler handles an event.
- #type_handles ⇒ Hash
Methods included from Utils
#on_format?, #respond_to?, #snakecase_class_name, #type_from_on_format
Instance Method Details
#default_handler(&block) ⇒ Proc
sets the default_handler, if called without a block, just assigns the default handler to a “default”
66 67 68 |
# File 'lib/vigilem/core/event_handler.rb', line 66 def default_handler(&block) type_handles.default = (block || lambda {|*args, &block| }) end |
#on(type, opts = {}, &block) ⇒ Proc Also known as: register_handle
TODO:
module_function
configures how this event handler handles an event
74 75 76 77 78 79 |
# File 'lib/vigilem/core/event_handler.rb', line 74 def on(type, opts={}, &block) type_name = snakecase_class_name(type) on_method = send(:_define_register, type, type_name) type_handles[type] = send(:_define_handler, type_name, &block) on_method.call(&block) end |
#type_handles ⇒ Hash
TODO:
Fuzzy is_a? Hash key lookup
57 58 59 |
# File 'lib/vigilem/core/event_handler.rb', line 57 def type_handles @type_handles ||= {} end |