Sha256: 3f57db0750359a3d42b06a7b108dd2700516d1f0bde8fec22696af6de4d60e7c

Contents?: true

Size: 1.03 KB

Versions: 32

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

# frozen_string_literal: true

module Karafka
  module Routing
    # Abstraction layer on top of groups of topics
    class Topics
      include Enumerable
      extend Forwardable

      def_delegators :@accumulator, :[], :size, :empty?, :last, :<<

      # @param topics_array [Array<Karafka::Routing::Topic>] array with topics
      def initialize(topics_array)
        @accumulator = topics_array.dup
      end

      # Yields each topic
      #
      # @param [Proc] block we want to yield with on each topic
      def each(&block)
        @accumulator.each(&block)
      end

      # Finds topic by its name
      #
      # @param topic_name [String] topic name
      # @return [Karafka::Routing::Topic]
      # @raise [Karafka::Errors::TopicNotFoundError] this should never happen. If you see it,
      #   please create an issue.
      def find(topic_name)
        @accumulator.find { |topic| topic.name == topic_name } ||
          raise(Karafka::Errors::TopicNotFoundError, topic_name)
      end
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
karafka-2.0.21 lib/karafka/routing/topics.rb
karafka-2.0.20 lib/karafka/routing/topics.rb
karafka-2.0.19 lib/karafka/routing/topics.rb
karafka-2.0.18 lib/karafka/routing/topics.rb
karafka-2.0.17 lib/karafka/routing/topics.rb
karafka-2.0.16 lib/karafka/routing/topics.rb
karafka-2.0.15 lib/karafka/routing/topics.rb
karafka-2.0.14 lib/karafka/routing/topics.rb
karafka-2.0.13 lib/karafka/routing/topics.rb
karafka-2.0.12 lib/karafka/routing/topics.rb
karafka-2.0.11 lib/karafka/routing/topics.rb
karafka-2.0.10 lib/karafka/routing/topics.rb
karafka-2.0.9 lib/karafka/routing/topics.rb
karafka-2.0.8 lib/karafka/routing/topics.rb
karafka-2.0.7 lib/karafka/routing/topics.rb
karafka-2.0.6 lib/karafka/routing/topics.rb
karafka-2.0.5 lib/karafka/routing/topics.rb
karafka-2.0.4 lib/karafka/routing/topics.rb
karafka-2.0.3 lib/karafka/routing/topics.rb
karafka-2.0.2 lib/karafka/routing/topics.rb