Sha256: fd1a268846f16c5cca3780bc1ca50d51bc42d7b62c2d19f5bb885408561ac3b3

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 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)
          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

1 entries across 1 versions & 1 rubygems

Version Path
dry-validation-0.8.0 lib/dry/validation/schema/check.rb