Sha256: e52048bd10c01a6c83d04e005b6d4519188440b783be0ee8ed65e246d9b8e0da

Contents?: true

Size: 1.07 KB

Versions: 13

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

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

            check_usage_with_other_params(opts, block)
            Utils::CheckOptIsStringOrSymbol.call(opts, :key)
          end

          private

          def check_usage_with_other_params(opts, block)
            raise SeregaError, "Option :key can not be used together with option :const" if opts.key?(:const)
            raise SeregaError, "Option :key can not be used together with option :value" if opts.key?(:value)
            raise SeregaError, "Option :key can not be used together with block" if block
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
serega-0.15.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.14.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.12.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.11.2 lib/serega/validations/attribute/check_opt_key.rb
serega-0.11.1 lib/serega/validations/attribute/check_opt_key.rb
serega-0.11.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.10.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.9.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.8.3 lib/serega/validations/attribute/check_opt_key.rb
serega-0.8.2 lib/serega/validations/attribute/check_opt_key.rb
serega-0.8.1 lib/serega/validations/attribute/check_opt_key.rb
serega-0.8.0 lib/serega/validations/attribute/check_opt_key.rb
serega-0.7.0 lib/serega/validations/attribute/check_opt_key.rb