Sha256: 6c5b66e2c309bdbe4570a5b7d4f0f3dd9ecb84ce189b924dd36b01ac0120d22d

Contents?: true

Size: 653 Bytes

Versions: 1

Compression:

Stored size: 653 Bytes

Contents

require 'dry/validation/schema'
require 'dry/validation/input_type_compiler'

module Dry
  module Validation
    class Schema::Form < Schema
      attr_reader :input_type

      def self.key(name, &block)
        if block
          super
        else
          super(name, &:filled?)
        end
      end

      def self.optional(name, &block)
        if block
          super
        else
          super(name, &:filled?)
        end
      end

      def initialize
        super
        @input_type = InputTypeCompiler.new.(self.class.rules.map(&:to_ary))
      end

      def call(input)
        super(input_type[input])
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dry-validation-0.6.0 lib/dry/validation/schema/form.rb