Class: Karafka::Declaratives::Builder
- Inherits:
-
Object
- Object
- Karafka::Declaratives::Builder
- Defined in:
- lib/karafka/declaratives/builder.rb
Overview
The main entry point for the declaratives subsystem. Returned by ‘Karafka::App.declaratives`. Provides the `draw` DSL and programmatic access to topic declarations and operations.
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#defaults(&block) ⇒ Object
Sets default values applied to every topic declared after this call.
-
#draw(&block) ⇒ Object
DSL entry point for declaring topics outside of routing blocks.
-
#find_topic(name) ⇒ Karafka::Declaratives::Topic?
Specific topic declaration.
-
#initialize ⇒ Builder
constructor
A new instance of Builder.
-
#topic(name, &block) ⇒ Karafka::Declaratives::Topic
Declares a topic with the given name.
-
#topics ⇒ Array<Karafka::Declaratives::Topic>
All active topic declarations.
Constructor Details
#initialize ⇒ Builder
Returns a new instance of Builder.
10 11 12 13 |
# File 'lib/karafka/declaratives/builder.rb', line 10 def initialize @repository = Repository.new @defaults = ->(_) {} end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
8 9 10 |
# File 'lib/karafka/declaratives/builder.rb', line 8 def repository @repository end |
Instance Method Details
#defaults(&block) ⇒ Object
Sets default values applied to every topic declared after this call. Defaults are evaluated before the topic block, so topic-specific values override them.
35 36 37 |
# File 'lib/karafka/declaratives/builder.rb', line 35 def defaults(&block) @defaults = block end |
#draw(&block) ⇒ Object
DSL entry point for declaring topics outside of routing blocks.
27 28 29 |
# File 'lib/karafka/declaratives/builder.rb', line 27 def draw(&block) instance_eval(&block) end |
#find_topic(name) ⇒ Karafka::Declaratives::Topic?
Returns specific topic declaration.
60 61 62 |
# File 'lib/karafka/declaratives/builder.rb', line 60 def find_topic(name) @repository.find(name) end |
#topic(name, &block) ⇒ Karafka::Declaratives::Topic
Declares a topic with the given name. If a topic with this name was already declared (via routing bridge or a prior draw call), the existing declaration is returned and the block is evaluated on it (allowing additive configuration).
46 47 48 49 50 51 |
# File 'lib/karafka/declaratives/builder.rb', line 46 def topic(name, &block) declaration = @repository.find_or_create(name) declaration.instance_eval(&@defaults) declaration.instance_eval(&block) if block declaration end |
#topics ⇒ Array<Karafka::Declaratives::Topic>
Returns all active topic declarations.
54 55 56 |
# File 'lib/karafka/declaratives/builder.rb', line 54 def topics @repository.active end |