Class: EventStoreClient::EventClassResolver

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

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ EventClassResolver

Returns a new instance of EventClassResolver.

Parameters:



9
10
11
# File 'lib/event_store_client/event_class_resolver.rb', line 9

def initialize(config)
  @config = config
end

Instance Method Details

#resolve(event_type) ⇒ Class<EventStoreClient::DeserializedEvent>

Parameters:

  • event_type (String, nil)

Returns:



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/event_store_client/event_class_resolver.rb', line 15

def resolve(event_type)
  return config.event_class_resolver.(event_type) || config.default_event_class if config.event_class_resolver

  Object.const_get(event_type)
rescue NameError, TypeError
  config.logger&.debug(<<~TEXT.strip)
    Unable to resolve class by `#{event_type}' event type. \
    Picking default `#{config.default_event_class}' event class to instantiate the event.
  TEXT
  config.default_event_class
end