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.



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

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



159
160
161
162
163
164
165
# File 'lib/aruba/event_bus/name_resolver.rb', line 159

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