Sha256: fb0eae637cec33e0f4fb0921345410a1c6f1dcc3afbe08be2136c8c9a6e55ff4

Contents?: true

Size: 1.13 KB

Versions: 10

Compression:

Stored size: 1.13 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) { |val| val.is_a?(String) && Contracts::TOPIC_REGEXP.match?(val) }
      required(:topics) { |val| val.is_a?(Array) && !val.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

10 entries across 10 versions & 1 rubygems

Version Path
karafka-2.0.15 lib/karafka/contracts/consumer_group.rb
karafka-2.0.14 lib/karafka/contracts/consumer_group.rb
karafka-2.0.13 lib/karafka/contracts/consumer_group.rb
karafka-2.0.12 lib/karafka/contracts/consumer_group.rb
karafka-2.0.11 lib/karafka/contracts/consumer_group.rb
karafka-2.0.10 lib/karafka/contracts/consumer_group.rb
karafka-2.0.9 lib/karafka/contracts/consumer_group.rb
karafka-2.0.8 lib/karafka/contracts/consumer_group.rb
karafka-2.0.7 lib/karafka/contracts/consumer_group.rb
karafka-2.0.6 lib/karafka/contracts/consumer_group.rb