Sha256: cde73b6b83a05e28b8493040aa6367a1fd6349bd25a4b438cb926dbdbc16e15d

Contents?: true

Size: 928 Bytes

Versions: 4

Compression:

Stored size: 928 Bytes

Contents

# frozen_string_literal: true

module WaterDrop
  module Contracts
    # Contract with validation rules for WaterDrop configuration details
    class Config < Base
      params do
        required(:id).filled(:str?)
        required(:logger).filled
        required(:deliver).filled(:bool?)
        required(:max_payload_size).filled(:int?, gteq?: 1)
        required(:max_wait_timeout).filled(:number?, gteq?: 0)
        required(:wait_timeout).filled(:number?, gt?: 0)
        required(:kafka).filled(:hash?)
      end

      # rdkafka allows both symbols and strings as keys for config but then casts them to strings
      # This can be confusing, so we expect all keys to be symbolized
      rule(:kafka) do
        next unless value.is_a?(Hash)

        value.each_key do |key|
          next if key.is_a?(Symbol)

          key(:"kafka.#{key}").failure(:kafka_key_must_be_a_symbol)
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
waterdrop-2.3.2 lib/waterdrop/contracts/config.rb
waterdrop-2.3.1 lib/waterdrop/contracts/config.rb
waterdrop-2.3.0 lib/waterdrop/contracts/config.rb
waterdrop-2.2.0 lib/waterdrop/contracts/config.rb