Module: Perennial::Dispatchable::ClassMethods
- Defined in:
- lib/perennial/dispatchable.rb
Instance Method Summary collapse
-
#handlers(recursive = true) ⇒ Object
Return an array of all registered handlers, ordered by their class and then the order of insertion.
-
#handlers=(new_value) ⇒ Object
Assigns a new array of handlers and assigns each - Note that this will only set this classes handlers, it will not override those for others above / below it in the inheritance chain.
-
#register_handler(handler) ⇒ Object
Appends a handler to the list of handlers for this object.
Instance Method Details
#handlers(recursive = true) ⇒ Object
Return an array of all registered handlers, ordered by their class and then the order of insertion. Please note that this will include ALL handlers up the inheritance chain unless false is passed as the only argument.
102 103 104 105 106 107 108 109 |
# File 'lib/perennial/dispatchable.rb', line 102 def handlers(recursive = true) handlers = [] if recursive && superclass.respond_to?(:handlers) handlers += superclass.handlers(recursive) end handlers += Dispatchable.handler_mapping[self] return handlers end |
#handlers=(new_value) ⇒ Object
Assigns a new array of handlers and assigns each - Note that this will only set this classes handlers, it will not override those for others above / below it in the inheritance chain.
114 115 116 117 |
# File 'lib/perennial/dispatchable.rb', line 114 def handlers=(new_value) Dispatchable.handler_mapping.delete self [*new_value].each { |h| register_handler h } end |
#register_handler(handler) ⇒ Object
Appends a handler to the list of handlers for this object. Handlers are called in the order they are registered.
121 122 123 124 125 126 |
# File 'lib/perennial/dispatchable.rb', line 121 def register_handler(handler) unless handler.blank? || !handler.respond_to?(:handle) handler.registered = true if handler.respond_to?(:registered=) Dispatchable.handler_mapping[self] << handler end end |