Module: Omnes::Subscriber::ClassMethods
- Defined in:
- lib/omnes/subscriber.rb
Overview
Included DSL methods for a Omnes::Subscriber
Instance Method Summary collapse
-
#handle(event_name, with:, id: Subscription.random_id) ⇒ Object
Match a single event name.
-
#handle_all(with:, id: Subscription.random_id) ⇒ Object
Handles all events.
-
#handle_with_matcher(matcher, with:, id: Subscription.random_id) ⇒ Object
Handles events with a custom matcher.
Instance Method Details
#handle(event_name, with:, id: Subscription.random_id) ⇒ Object
Match a single event name
196 197 198 199 200 201 202 203 |
# File 'lib/omnes/subscriber.rb', line 196 def handle(event_name, with:, id: Subscription.random_id) @_mutex.synchronize do @_state.add_subscription_definition do |bus, instance| bus.registry.check_event_name(event_name) [Subscription::SINGLE_EVENT_MATCHER.curry[event_name], Adapter.Type(with), State.IdType(id).(instance)] end end end |
#handle_all(with:, id: Subscription.random_id) ⇒ Object
Handles all events
209 210 211 212 213 214 215 |
# File 'lib/omnes/subscriber.rb', line 209 def handle_all(with:, id: Subscription.random_id) @_mutex.synchronize do @_state.add_subscription_definition do |_bus, instance| [Subscription::ALL_EVENTS_MATCHER, Adapter.Type(with), State.IdType(id).(instance)] end end end |
#handle_with_matcher(matcher, with:, id: Subscription.random_id) ⇒ Object
Handles events with a custom matcher
222 223 224 225 226 227 228 |
# File 'lib/omnes/subscriber.rb', line 222 def handle_with_matcher(matcher, with:, id: Subscription.random_id) @_mutex.synchronize do @_state.add_subscription_definition do |_bus, instance| [matcher, Adapter.Type(with), State.IdType(id).(instance)] end end end |