Class: Aruba::EventBus::NameResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/event_bus/name_resolver.rb

Overview

Resolve name to Event name

Defined Under Namespace

Modules: ResolveHelpers Classes: ClassResolver, FailingResolver, StringResolver, SymbolResolver

Instance Method Summary collapse

Constructor Details

#initialize(default_namespace) ⇒ NameResolver

Returns a new instance of NameResolver.


139
140
141
142
143
144
145
146
147
# File 'lib/aruba/event_bus/name_resolver.rb', line 139

def initialize(default_namespace)
  @default_namespace = default_namespace

  @resolvers = []
  @resolvers << ClassResolver
  @resolvers << StringResolver
  @resolvers << SymbolResolver
  @resolvers << FailingResolver
end

Instance Method Details

#transform(event_id) ⇒ Object


149
150
151
152
153
154
155
# File 'lib/aruba/event_bus/name_resolver.rb', line 149

def transform(event_id)
  resolvers.find { |r| r.match? event_id }.new.transform(default_namespace, event_id)
rescue => e
  # rubocop:disable Metrics/LineLength
  raise EventNameResolveError, %(Transforming "#{event_id}" into an event class failed. Supported types are: #{@resolvers.map(&:supports).flatten.join(', ')}. #{e.message}.\n\n#{e.backtrace.join("\n")})
  # rubocop:enable Metrics/LineLength
end