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
140 141 142 143 144 |
# File 'lib/perennial/dispatchable.rb', line 140 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.
114 115 116 117 118 119 120 121 |
# File 'lib/perennial/dispatchable.rb', line 114 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.
126 127 128 129 |
# File 'lib/perennial/dispatchable.rb', line 126 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.
133 134 135 136 137 138 |
# File 'lib/perennial/dispatchable.rb', line 133 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
151 152 153 154 155 156 |
# File 'lib/perennial/dispatchable.rb', line 151 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
146 147 148 149 |
# File 'lib/perennial/dispatchable.rb', line 146 def reloading! handlers = Dispatchable.handler_mapping.delete(self) Dispatchable.reloading_mapping[self.name] = handlers end |