Module: Perennial::Dispatchable::ClassMethods

Defined in:
lib/perennial/dispatchable.rb

Instance Method Summary collapse

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.



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



137
138
139
140
141
142
# File 'lib/perennial/dispatchable.rb', line 137

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



132
133
134
135
# File 'lib/perennial/dispatchable.rb', line 132

def reloading!
  handlers = Dispatchable.handler_mapping.delete(self)
  Dispatchable.reloading_mapping[self.name] = handlers
end