Module: Omnes::Event
- Extended by:
- Configurable
- Defined in:
- lib/omnes/event.rb
Overview
Event mixin for custom classes
Any instance of a class including this one can be used as a published event (see Bus#publish).
class MyEvent
include Omnes::Event
attr_reader :event
def initialize(id:)
@id = id
end
end
bus = Omnes::Bus.new
bus.register(:my_event)
bus.subscribe(:my_event) do |event|
puts event.id
end
bus.publish(MyEvent.new(1))
Constant Summary collapse
- DEFAULT_NAME_BUILDER =
Generates the event name for an event instance
It returns the underscored class name, with an
Event
suffix removed if present. E.g:- Foo ->
:foo
- FooEvent ->
:foo
- FooBar ->
:foo_bar
- FBar ->
:f_bar
- Foo::Bar ->
:foo_bar
You can also use your custom name builder. It needs to be something callable taking the instance as argument and returning a Symbol:
my_name_builder = ->(instance) { instance.class.name.to_sym } Omnes.config.event.name_builder = my_name_builder
- Foo ->
lambda do |instance| instance.class.name .chomp("Event") .gsub(/([[:alpha:]])([[:upper:]])/, '\1_\2') .gsub("::", "_") .downcase .to_sym end
Class Method Summary collapse
-
.config ⇒ Configurable::Config
extended
from Configurable
Returns the configuration class.
-
.configure {|@config| ... } ⇒ Object
extended
from Configurable
Yields the configuration class.
- .nest_config(constant, name: default_nesting_name(constant)) ⇒ Object extended from Configurable private
- .setting(name, default:) ⇒ Object extended from Configurable private
Instance Method Summary collapse
-
#omnes_event_name ⇒ Symbol
Event name.
Class Method Details
.config ⇒ Configurable::Config Originally defined in module Configurable
Returns the configuration class
Use this class to access readers and writers for the defined settings or nested configurations
.configure {|@config| ... } ⇒ Object Originally defined in module Configurable
Yields the configuration class
.nest_config(constant, name: default_nesting_name(constant)) ⇒ Object Originally defined in module Configurable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
.setting(name, default:) ⇒ Object Originally defined in module Configurable
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.