Module: Seams::Events

Defined in:
lib/seams/events.rb,
lib/seams/events/adapter.rb,
lib/seams/events/publisher.rb,
lib/seams/events/adapters/active_support.rb

Overview

Events module — public API for inter-engine communication.

Engines publish domain events through Seams::Events::Publisher and subscribe to events from other engines via the same module. Subscribers are expected to enqueue background jobs rather than perform side effects synchronously, so that the publisher’s transaction can commit quickly and side effects can retry independently.

Defined Under Namespace

Modules: Adapters, Publisher Classes: Adapter, DuplicateEventError, Error, InvalidEventNameError, UnregisteredEventError

Constant Summary collapse

NAME_PATTERN =

Three dot-separated segments, lowercase, snake_case allowed.

/\A[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\.[a-z][a-z0-9_]*\z/

Class Method Summary collapse

Class Method Details

.assert_valid_name!(name) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/seams/events.rb', line 31

def self.assert_valid_name!(name)
  return if valid_name?(name)

  raise InvalidEventNameError,
        "Event name #{name.inspect} must follow resource.action.engine " \
        "(e.g. subscription.created.billing)"
end

.valid_name?(name) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/seams/events.rb', line 27

def self.valid_name?(name)
  NAME_PATTERN.match?(name.to_s)
end