Sha256: 2b20ddfe363dee0543fa650c98c6ccc58221405c47aae19c787e0c142df34f1f

Contents?: true

Size: 885 Bytes

Versions: 6

Compression:

Stored size: 885 Bytes

Contents

module Dry
  module Validation
    class Schema
      class Check < Value
        def class
          Check
        end

        def schema(other = nil, &block)
          schema = Schema.create_class(self, other, &block)

          if other
            schema.config.input_processor = other.class.config.input_processor
          end

          hash?.and(create_rule([:check, [name, schema.to_ast], [path]]))
        end

        private

        def method_missing(meth, *meth_args)
          vals, args = meth_args.partition { |arg| arg.class < DSL }

          keys = [name, *vals.map(&:name)]

          registry.ensure_valid_predicate(meth, args.size + keys.size, schema_class)
          predicate = registry[meth].curry(*args)

          rule = create_rule([:check, [name, predicate.to_ast, keys]])
          add_rule(rule)
          rule
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
dry-validation-0.9.5 lib/dry/validation/schema/check.rb
dry-validation-0.9.4 lib/dry/validation/schema/check.rb
dry-validation-0.9.3 lib/dry/validation/schema/check.rb
dry-validation-0.9.2 lib/dry/validation/schema/check.rb
dry-validation-0.9.1 lib/dry/validation/schema/check.rb
dry-validation-0.9.0 lib/dry/validation/schema/check.rb