Module: Omnes::Subscriber::ClassMethods

Defined in:
lib/omnes/subscriber.rb

Overview

Included DSL methods for a Omnes::Subscriber

Instance Method Summary collapse

Instance Method Details

#handle(event_name, with:, id: Subscription.random_id) ⇒ Object

Match a single event name

Parameters:

  • event_name (Symbol)
  • with (Symbol, #call)

    Public method in the class or an adapter

  • id (Symbol) (defaults to: Subscription.random_id)

    Unique identifier for the subscription



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

Parameters:

  • with (Symbol, #call)

    Public method in the class or an adapter

  • id (Symbol) (defaults to: Subscription.random_id)

    Unique identifier for the subscription



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

Parameters:

  • matcher (#call)
  • with (Symbol, #call)

    Public method in the class or an adapter

  • id (Symbol) (defaults to: Subscription.random_id)

    Unique identifier for the subscription



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