Sha256: b332fc0dc4f23144bbaed1a38cc27705113108b7e9cbc128beecd29e83efd586

Contents?: true

Size: 596 Bytes

Versions: 7

Compression:

Stored size: 596 Bytes

Contents

# frozen_string_literal: true

module Atacama
  # A description of the signature of the parameter being validated
  class Parameter
    attr_reader :name, :type

    def initialize(name:, type: nil)
      @name = name
      @type = type
    end

    # Determine the validity of a value for an optionally given type. Raises a
    # type error on failure.
    # @raise [Atacama::TypeError]
    # @returns Boolean
    def valid?(value)
      return true if type.nil?
      type[value]
      true
    rescue Dry::Types::ConstraintError => error
      raise TypeError, error.message
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
atacama-0.1.6 lib/atacama/contract/parameter.rb
atacama-0.1.5 lib/atacama/contract/parameter.rb
atacama-0.1.4 lib/atacama/contract/parameter.rb
atacama-0.1.3 lib/atacama/contract/parameter.rb
atacama-0.1.2 lib/atacama/contract/parameter.rb
atacama-0.1.1 lib/atacama/contract/parameter.rb
atacama-0.1.0 lib/atacama/contract/parameter.rb