Class: EventStoreClient::EventClassResolver
- Inherits:
-
Object
- Object
- EventStoreClient::EventClassResolver
- Defined in:
- lib/event_store_client/event_class_resolver.rb
Instance Method Summary collapse
-
#initialize(config) ⇒ EventClassResolver
constructor
A new instance of EventClassResolver.
- #resolve(event_type) ⇒ Class<EventStoreClient::DeserializedEvent>
Constructor Details
#initialize(config) ⇒ EventClassResolver
Returns a new instance of EventClassResolver.
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>
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 |