Class: Karafka::Responders::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/karafka/responders/builder.rb

Overview

Responders builder is used for finding (based on the consumer class name) a responder that match the consumer. We use it when user does not provide a responder inside routing, but he still names responder with the same convention (and namespaces) as consumer

Examples:

Matching responder exists

Karafka::Responder::Builder(NewEventsConsumer).build #=> NewEventsResponder

Matching responder does not exist

Karafka::Responder::Builder(NewBuildsConsumer).build #=> nil

Instance Method Summary collapse

Constructor Details

#initialize(consumer_class) ⇒ Builder

Returns a new instance of Builder.

Examples:

Tries to find a responder that matches a given consumer. If nothing found,

will return nil (nil is accepted, because it means that a given consumer don't
pipe stuff further on)

Parameters:



20
21
22
# File 'lib/karafka/responders/builder.rb', line 20

def initialize(consumer_class)
  @consumer_class = consumer_class
end

Instance Method Details

#buildClass?

Tries to figure out a responder based on a consumer class name

Returns:

  • (Class)

    Responder class (not an instance)

  • (nil)

    or nil if there’s no matching responding class



27
28
29
30
31
32
33
# File 'lib/karafka/responders/builder.rb', line 27

def build
  Helpers::ClassMatcher.new(
    @consumer_class,
    from: 'Consumer',
    to: 'Responder'
  ).match
end