Class: Yes::Core::EventClassResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/yes/core/event_class_resolver.rb

Overview

Resolves PgEventstore event types back into their proper class. When configured as the event_class_resolver in PgEventstore, events deserialized from the store will be instances of their registered class (e.g., ‘Test::UserCreated < Yes::Core::Event`) instead of raw `PgEventstore::Event`.

Defined Under Namespace

Classes: SkipValidationProxy

Instance Method Summary collapse

Instance Method Details

#call(event_type) ⇒ #new

Resolves an event type string to its class.

Parameters:

  • event_type (String)

    the event type (e.g., “Test::UserCreated”)

Returns:

  • (#new)

    the event class or a proxy that skips validation



29
30
31
32
33
34
35
36
37
# File 'lib/yes/core/event_class_resolver.rb', line 29

def call(event_type)
  SkipValidationProxy.new(Object.const_get(event_type))
rescue NameError, TypeError
  PgEventstore.logger&.debug(<<~TEXT.strip)
    Unable to resolve class by `#{event_type}' event type. \
    Picking #{Event} event class to instantiate the event.
  TEXT
  Event
end