Sha256: f81334227265cc437c06cf635228f133fca8066d91006d64c9d60aea9aae04bb

Contents?: true

Size: 1.33 KB

Versions: 3

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module Karafka
  module Web
    module Tracking
      module Consumers
        module Contracts
          # Expected data for each subscription group
          # It's mostly about topics details
          class SubscriptionGroup < Web::Contracts::Base
            configure

            required(:id) { |val| val.is_a?(String) && !val.empty? }
            required(:topics) { |val| val.is_a?(Hash) }

            nested(:state) do
              required(:state) { |val| val.is_a?(String) && !val.empty? }
              required(:join_state) { |val| val.is_a?(String) && !val.empty? }
              required(:stateage) { |val| val.is_a?(Integer) && val >= 0 }
              required(:rebalance_age) { |val| val.is_a?(Integer) && val >= 0 }
              required(:rebalance_cnt) { |val| val.is_a?(Integer) && val >= 0 }
              required(:rebalance_reason) { |val| val.is_a?(String) && !val.empty? }
              required(:poll_age) { |val| val.is_a?(Numeric) && val >= 0 }
            end

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

              topic_contract = Topic.new

              data.fetch(:topics).each_value do |details|
                topic_contract.validate!(details)
              end

              nil
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
karafka-web-0.8.1 lib/karafka/web/tracking/consumers/contracts/subscription_group.rb
karafka-web-0.8.0 lib/karafka/web/tracking/consumers/contracts/subscription_group.rb
karafka-web-0.8.0.rc1 lib/karafka/web/tracking/consumers/contracts/subscription_group.rb