Sha256: 5578cc055fb11999f44c83e3d645cdd314f142783d8469deaaac64a2a7825be7

Contents?: true

Size: 807 Bytes

Versions: 1

Compression:

Stored size: 807 Bytes

Contents

# frozen_string_literal: true

module Atacama
  # Validation execution class for a given set of parameters and options.
  class Validator
    def self.call(**context)
      new(**context).call
    end

    # @param options [Hash] options schema
    # @param context [Atacama::Context] keyword arguments to validate
    def initialize(options:, context:, klass:)
      @options = options
      @context = context
      @klass = klass
    end

    def call
      detect_invalid_types!
    end

    private

    attr_reader :options, :context, :klass

    def detect_invalid_types!
      options.each do |key, parameter|
        Atacama.check(parameter.type, context[key]) do |e|
          raise OptionTypeMismatchError, %(#{klass} option :#{key} invalid: #{e.message})
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
atacama-0.1.8 lib/atacama/contract/validator.rb