Sha256: c2938073b14a50158a980069bbfe13c4efaf51676e3cf1479e256493c60e448c

Contents?: true

Size: 1.14 KB

Versions: 11

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Karafka
  module Contracts
    # Contract for single full route (consumer group + topics) validation.
    class ConsumerGroup < Base
      configure do |config|
        config.error_messages = YAML.safe_load(
          File.read(
            File.join(Karafka.gem_root, 'config', 'errors.yml')
          )
        ).fetch('en').fetch('validations').fetch('consumer_group')
      end

      required(:id) { |id| id.is_a?(String) && Contracts::TOPIC_REGEXP.match?(id) }
      required(:topics) { |topics| topics.is_a?(Array) && !topics.empty? }

      virtual do |data, errors|
        next unless errors.empty?

        names = data.fetch(:topics).map { |topic| topic[:name] }

        next if names.size == names.uniq.size

        [[%i[topics], :names_not_unique]]
      end

      virtual do |data, errors|
        next unless errors.empty?

        fetched_errors = []

        data.fetch(:topics).each do |topic|
          ConsumerGroupTopic.new.call(topic).errors.each do |key, value|
            fetched_errors << [[topic, key].flatten, value]
          end
        end

        fetched_errors
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
karafka-2.0.5 lib/karafka/contracts/consumer_group.rb
karafka-2.0.4 lib/karafka/contracts/consumer_group.rb
karafka-2.0.3 lib/karafka/contracts/consumer_group.rb
karafka-2.0.2 lib/karafka/contracts/consumer_group.rb
karafka-2.0.1 lib/karafka/contracts/consumer_group.rb
karafka-2.0.0 lib/karafka/contracts/consumer_group.rb
karafka-2.0.0.rc6 lib/karafka/contracts/consumer_group.rb
karafka-2.0.0.rc5 lib/karafka/contracts/consumer_group.rb
karafka-2.0.0.rc4 lib/karafka/contracts/consumer_group.rb
karafka-2.0.0.rc3 lib/karafka/contracts/consumer_group.rb
karafka-2.0.0.rc2 lib/karafka/contracts/consumer_group.rb