Class: Karafka::Routing::Topics

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/karafka/routing/topics.rb

Overview

Abstraction layer on top of groups of topics

Instance Method Summary collapse

Constructor Details

#initialize(topics_array) ⇒ Topics

Returns a new instance of Topics.

Parameters:



15
16
17
# File 'lib/karafka/routing/topics.rb', line 15

def initialize(topics_array)
  @accumulator = topics_array.dup
end

Instance Method Details

#delete_if(&block) ⇒ Object

Allows us to remove elements from the topics

Block to decide what to delete

Parameters:

  • block (Proc)


30
31
32
# File 'lib/karafka/routing/topics.rb', line 30

def delete_if(&block)
  @accumulator.delete_if(&block)
end

#each(&block) ⇒ Object

Yields each topic

Parameters:

  • block (Proc)

    we want to yield with on each topic



22
23
24
# File 'lib/karafka/routing/topics.rb', line 22

def each(&block)
  @accumulator.each(&block)
end

#find(topic_name) ⇒ Karafka::Routing::Topic

Finds topic by its name

Parameters:

  • topic_name (String)

    topic name

Returns:

Raises:



40
41
42
43
# File 'lib/karafka/routing/topics.rb', line 40

def find(topic_name)
  @accumulator.find { |topic| topic.name == topic_name } ||
    raise(Karafka::Errors::TopicNotFoundError, topic_name)
end