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.



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

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



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

def transform(event_id)
  resolvers.find { |r| r.match? event_id }.new.transform(default_namespace, event_id)
rescue StandardError => e
  types = @resolvers.map(&:supports).flatten.join(", ")
  message = "Transforming \"#{event_id}\" into an event class failed." \
            " Supported types are: #{types}. #{e.message}."
  raise EventNameResolveError, message, cause: e
end