Sha256: b2553f944897c4d610e654d2c11a513cc70b10f6815672c1c6eb8db23303a445

Contents?: true

Size: 1 KB

Versions: 8

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

class Serega
  module SeregaValidations
    module Attribute
      #
      # Attribute `:many` option validator
      #
      class CheckOptMany
        class << self
          #
          # Checks attribute :many option
          #
          # @param opts [Hash] Attribute options
          #
          # @raise [SeregaError] SeregaError that option has invalid value
          #
          # @return [void]
          #
          def call(opts)
            return unless opts.key?(:many)

            check_many_option_makes_sence(opts)
            Utils::CheckOptIsBool.call(opts, :many)
          end

          private

          def check_many_option_makes_sence(opts)
            return if many_option_makes_sence?(opts)

            raise SeregaError, "Option :many can be provided only together with :serializer or :batch option"
          end

          def many_option_makes_sence?(opts)
            opts[:serializer] || opts[:batch]
          end
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
serega-0.21.0 lib/serega/validations/attribute/check_opt_many.rb
serega-0.20.1 lib/serega/validations/attribute/check_opt_many.rb
serega-0.20.0 lib/serega/validations/attribute/check_opt_many.rb
serega-0.19.0 lib/serega/validations/attribute/check_opt_many.rb
serega-0.18.0 lib/serega/validations/attribute/check_opt_many.rb
serega-0.17.0 lib/serega/validations/attribute/check_opt_many.rb
serega-0.16.0 lib/serega/validations/attribute/check_opt_many.rb
serega-0.15.0 lib/serega/validations/attribute/check_opt_many.rb