Sha256: 3e7c030070604564dd0c9b42db816994a9670adf695dc3b1a45dd844e6452f6c

Contents?: true

Size: 645 Bytes

Versions: 1

Compression:

Stored size: 645 Bytes

Contents

# Validates a type, given an input, type and options
# output is a coerced value
# error is an array of strings
module Compel
  module Validators

    class TypeValidator < Base

      def initialize(input, schema)
        super
        @output = nil
      end

      def validate
        value = input.nil? ? schema.default_value : input

        begin
          @output = Coercion.coerce!(value, schema.type, schema.options)
          @errors = Validation.validate(value, schema.type, schema.options)
        rescue Compel::TypeError => exception
          @errors = [exception.message]
        end

        self
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
compel-0.2.0 lib/compel/validators/type_validator.rb