Module: Octiron::World
- Extended by:
- ClassMethods
- Defined in:
- lib/octiron/world.rb
Overview
World module, putting together the event bus and transmogrifier registry with easy access functions.
Defined Under Namespace
Modules: ClassMethods Classes: AutoTransmogrifyDelegator, TransmogrifierRegistrator, TransmogrifyDelegator
Instance Method Summary collapse
-
#autotransmogrify(from, options = {}) ⇒ Object
Automatically transmogrify one event type to another, and publish the result.
-
#on_event(event_id, handler_object = nil, handler_class = ::Octiron::Events::Bus::DEFAULT_CLASS, &handler_proc) ⇒ Object
Subscribe an event handler to an event with the singleton event bus.
-
#on_transmogrify(from) ⇒ Object
Register a transmogrifier with the singleton transmogrifier registry.
-
#publish(event) ⇒ Object
Publish an event on the singleton event bus.
-
#transmogrify(from) ⇒ Object
Transmogrify using the singleton transmogrifier registry.
Methods included from ClassMethods
event_bus, transmogrifier_registry
Instance Method Details
#autotransmogrify(from, options = {}) ⇒ Object
Automatically transmogrify one event type to another, and publish the result. By default, a transmogrifier that returns a nil object simply does not publish a result.
110 111 112 113 |
# File 'lib/octiron/world.rb', line 110 def autotransmogrify(from, = {}) raise_on_nil = [:raise_on_nil] || false return AutoTransmogrifyDelegator.new(from, raise_on_nil) end |
#on_event(event_id, handler_object = nil, handler_class = ::Octiron::Events::Bus::DEFAULT_CLASS, &handler_proc) ⇒ Object
Subscribe an event handler to an event with the singleton event bus
123 124 125 126 127 128 |
# File 'lib/octiron/world.rb', line 123 def on_event(event_id, handler_object = nil, handler_class = ::Octiron::Events::Bus::DEFAULT_CLASS, &handler_proc) ::Octiron::World.event_bus.subscribe(event_id, handler_object, handler_class, &handler_proc) end |
#on_transmogrify(from) ⇒ Object
Register a transmogrifier with the singleton transmogrifier registry
102 103 104 |
# File 'lib/octiron/world.rb', line 102 def on_transmogrify(from) return TransmogrifierRegistrator.new(from) end |
#publish(event) ⇒ Object
Publish an event on the singleton event bus
132 133 134 |
# File 'lib/octiron/world.rb', line 132 def publish(event) ::Octiron::World.event_bus.publish(event) end |
#transmogrify(from) ⇒ Object
Transmogrify using the singleton transmogrifier registry
117 118 119 |
# File 'lib/octiron/world.rb', line 117 def transmogrify(from) return TransmogrifyDelegator.new(from) end |