Class: Realm::DomainResolver

Inherits:
Object
  • Object
show all
Defined in:
lib/realm/domain_resolver.rb

Constant Summary collapse

DOMAIN_CLASS_TYPES =
[CommandHandler, QueryHandler, EventHandler].freeze

Instance Method Summary collapse

Constructor Details

#initialize(domain_module = nil) ⇒ DomainResolver

Returns a new instance of DomainResolver.



7
8
9
10
11
12
# File 'lib/realm/domain_resolver.rb', line 7

def initialize(domain_module = nil)
  # nil domain resolver is useful in tests
  @domain_module = domain_module
  @index = DOMAIN_CLASS_TYPES.map { |t| [t, {}] }.to_h
  scan(domain_module) if domain_module
end

Instance Method Details

#all_event_handlersObject



27
28
29
# File 'lib/realm/domain_resolver.rb', line 27

def all_event_handlers
  @index[EventHandler].values
end

#get_handler_with_action(type, identifier) ⇒ Object



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

def get_handler_with_action(type, identifier)
  handlers = @index[type]
  return [handlers[identifier], :handle] if handlers.key?(identifier)

  # The last part of the identifier can be action method name inside the handler
  parts = identifier.split('.')
  handler_part = parts[..-2].join('.')
  action = parts[-1]
  return [handlers[handler_part], action.to_sym] if handlers.key?(handler_part)

  [nil, nil]
end