Class: Karafka::Responders::Builder

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

Overview

Responders builder is used to find (based on the controller class name) a responder that match the controller. This is used when user does not provide a responder inside routing but he still names responder with the same convention (and namespaces) as controller

Examples:

Matching responder exists

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

Matching responder does not exist

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

Instance Method Summary collapse

Constructor Details

#initialize(controller_class) ⇒ Builder

Returns a new instance of Builder.

Examples:

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

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

Parameters:



17
18
19
# File 'lib/karafka/responders/builder.rb', line 17

def initialize(controller_class)
  @controller_class = controller_class
end

Instance Method Details

#buildClass?

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

Returns:

  • (Class)

    Responder class (not an instance)

  • (nil)

    or nil if there’s no matching responding class



24
25
26
27
28
29
30
# File 'lib/karafka/responders/builder.rb', line 24

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