Module: Perennial::Dispatchable::ClassMethods
- Defined in:
- lib/perennial/dispatchable.rb
Instance Method Summary collapse
- #delete_handler(handler) ⇒ Object
-
#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.
- #reloaded! ⇒ Object
- #reloading! ⇒ Object
Instance Method Details
#delete_handler(handler) ⇒ Object
132 133 134 135 136 |
# File 'lib/perennial/dispatchable.rb', line 132 def delete_handler(handler) return if handler.blank? handler.registered = false if handler.respond_to?(:registered=) Dispatchable.handler_mapping[self].delete(handler) end |
#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.
106 107 108 109 110 111 112 113 |
# File 'lib/perennial/dispatchable.rb', line 106 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.
118 119 120 121 |
# File 'lib/perennial/dispatchable.rb', line 118 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.
125 126 127 128 129 130 |
# File 'lib/perennial/dispatchable.rb', line 125 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 |
#reloaded! ⇒ Object
143 144 145 146 147 148 |
# File 'lib/perennial/dispatchable.rb', line 143 def reloaded! if Dispatchable.reloading_mapping.has_key?(self.name) handlers = Dispatchable.reloading_mapping.delete(self.name) handlers.each { |h| register_handler(h) } end end |
#reloading! ⇒ Object
138 139 140 141 |
# File 'lib/perennial/dispatchable.rb', line 138 def reloading! handlers = Dispatchable.handler_mapping.delete(self) Dispatchable.reloading_mapping[self.name] = handlers end |