class Karafka::Responders::Builder

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

@example Matching responder exists

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

@example Matching responder does not exist

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

Public Class Methods

new(consumer_class) click to toggle source

@param consumer_class [Karafka::BaseConsumer, nil] descendant of

Karafka::BaseConsumer

@example 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)
# File lib/karafka/responders/builder.rb, line 20
def initialize(consumer_class)
  @consumer_class = consumer_class
end

Public Instance Methods

build() click to toggle source

Tries to figure out a responder based on a consumer class name @return [Class] Responder class (not an instance) @return [nil] or nil if there's no matching responding class

# File lib/karafka/responders/builder.rb, line 27
def build
  Helpers::ClassMatcher.new(
    @consumer_class,
    from: 'Consumer',
    to: 'Responder'
  ).match
end