Class: Marvin::MiddleMan
- Inherits:
-
Object
- Object
- Marvin::MiddleMan
- Defined in:
- lib/marvin/middle_man.rb
Overview
The middle man is a class you can use to register other handlers on. e.g. it acts as a way to ‘filter’ incoming and outgoing messages. Akin to Rack / WSGI middleware.
Constant Summary collapse
- @@setup =
By default, we are not setup.
false
Instance Attribute Summary collapse
-
#client ⇒ Object
Finally, the client.
Class Method Summary collapse
-
.register_handler(handler, run_setup = true) ⇒ Object
Register a single subhandler.
-
.register_handlers(*args) ⇒ Object
Registers a group of subhandlers.
-
.setup ⇒ Object
Setup iff setup hasn’t been done.
-
.setup! ⇒ Object
Forcefully do the setup routine.
- .setup? ⇒ Boolean
Instance Method Summary collapse
-
#handle(message, options) ⇒ Object
Filter incoming events.
- #process_event(message, options) ⇒ Object
Instance Attribute Details
#client ⇒ Object
Finally, the client.
21 22 23 |
# File 'lib/marvin/middle_man.rb', line 21 def client @client end |
Class Method Details
.register_handler(handler, run_setup = true) ⇒ Object
Register a single subhandler.
72 73 74 75 |
# File 'lib/marvin/middle_man.rb', line 72 def register_handler(handler, run_setup = true) self.setup if run_setup self.subhandlers << handler unless handler.blank? end |
.register_handlers(*args) ⇒ Object
Registers a group of subhandlers.
78 79 80 81 |
# File 'lib/marvin/middle_man.rb', line 78 def register_handlers(*args) self.setup args.each { |h| self.register_handler(h, false) } end |
.setup ⇒ Object
Setup iff setup hasn’t been done.
66 67 68 69 |
# File 'lib/marvin/middle_man.rb', line 66 def setup return if self.setup? self.setup! end |
.setup! ⇒ Object
Forcefully do the setup routine.
59 60 61 62 63 |
# File 'lib/marvin/middle_man.rb', line 59 def setup! # Register ourselves as a new handler. Marvin::Settings.client.register_handler self.new @@setup = true end |
.setup? ⇒ Boolean
54 55 56 |
# File 'lib/marvin/middle_man.rb', line 54 def setup? @@setup end |
Instance Method Details
#handle(message, options) ⇒ Object
Filter incoming events.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/marvin/middle_man.rb', line 37 def handle(, ) # Process the current event. , = process_event(, ) full_handler_name = "handle_#{}" self.send(full_handler_name, opts) if respond_to?(full_handler_name) self.subhandlers.each do |sh| (sh, , , full_handler_name) end rescue HaltHandlerProcessing logger.info "Asked to halt the filter processing chain inside a middleman." rescue Exception => e logger.fatal "Exception processing handle #{}" Marvin::ExceptionTracker.log(e) end |
#process_event(message, options) ⇒ Object
32 33 34 |
# File 'lib/marvin/middle_man.rb', line 32 def process_event(, ) return , end |