Class: Karafka::Declaratives::Repository
- Inherits:
-
Object
- Object
- Karafka::Declaratives::Repository
- Defined in:
- lib/karafka/declaratives/repository.rb
Overview
Holds all topic declarations. Single source of truth for “what topics have been declared.” Both the new DSL and the routing bridge populate this repository.
Instance Method Summary collapse
-
#active ⇒ Array<Karafka::Declaratives::Topic>
All declarations where active? is true.
-
#clear ⇒ Object
Removes all declarations.
-
#each(&block) ⇒ Object
Iterates over all declarations.
-
#empty? ⇒ Boolean
Are there any declarations.
-
#find(name) ⇒ Karafka::Declaratives::Topic?
The declaration or nil.
-
#find_or_create(name) ⇒ Karafka::Declaratives::Topic
Finds an existing declaration or creates a new one for the given topic name.
-
#initialize ⇒ Repository
constructor
A new instance of Repository.
-
#size ⇒ Integer
Number of declarations.
Constructor Details
#initialize ⇒ Repository
Returns a new instance of Repository.
8 9 10 |
# File 'lib/karafka/declaratives/repository.rb', line 8 def initialize @topics = {} end |
Instance Method Details
#active ⇒ Array<Karafka::Declaratives::Topic>
Returns all declarations where active? is true.
20 21 22 |
# File 'lib/karafka/declaratives/repository.rb', line 20 def active @topics.values.select(&:active?) end |
#clear ⇒ Object
Removes all declarations
47 48 49 |
# File 'lib/karafka/declaratives/repository.rb', line 47 def clear @topics.clear end |
#each(&block) ⇒ Object
Iterates over all declarations
32 33 34 |
# File 'lib/karafka/declaratives/repository.rb', line 32 def each(&block) @topics.each_value(&block) end |
#empty? ⇒ Boolean
Returns are there any declarations.
42 43 44 |
# File 'lib/karafka/declaratives/repository.rb', line 42 def empty? @topics.empty? end |
#find(name) ⇒ Karafka::Declaratives::Topic?
Returns the declaration or nil.
26 27 28 |
# File 'lib/karafka/declaratives/repository.rb', line 26 def find(name) @topics[name.to_s] end |
#find_or_create(name) ⇒ Karafka::Declaratives::Topic
Finds an existing declaration or creates a new one for the given topic name
15 16 17 |
# File 'lib/karafka/declaratives/repository.rb', line 15 def find_or_create(name) @topics[name.to_s] ||= Topic.new(name) end |
#size ⇒ Integer
Returns number of declarations.
37 38 39 |
# File 'lib/karafka/declaratives/repository.rb', line 37 def size @topics.size end |