Class: Karafka::Workers::Builder

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

Overview

Builder is used to check if there is a proper controller with the same name as a controller and if not, it will create a default one using Karafka::BaseWorker This is used as a building layer between controllers and workers. it will be only used when user does not provide his own worker that should perform controller stuff

Instance Method Summary collapse

Constructor Details

#initialize(controller_class) ⇒ Builder

Returns a new instance of Builder.

Examples:

Create a worker builder

Karafka::Workers::Builder.new(SuperController)

Parameters:



12
13
14
# File 'lib/karafka/workers/builder.rb', line 12

def initialize(controller_class)
  @controller_class = controller_class
end

Instance Method Details

#buildClass

Returns Sidekiq worker class that already exists or new build based on the provided controller_class name.

Examples:

Controller: SuperController

build #=> SuperWorker

Controller: Videos::NewVideosController

build #=> Videos::NewVideosWorker

Returns:

  • (Class)

    Sidekiq worker class that already exists or new build based on the provided controller_class name



22
23
24
25
26
# File 'lib/karafka/workers/builder.rb', line 22

def build
  return matcher.match if matcher.match
  klass = Class.new(base)
  matcher.scope.const_set(matcher.name, klass)
end