Class: Dry::Validation::Schema::Check

Inherits:
Value
  • Object
show all
Defined in:
lib/dry/validation/schema/check.rb

Instance Attribute Summary

Attributes inherited from Value

#schema_class, #type, #type_map

Attributes inherited from DSL

#checks, #name, #options, #parent, #registry, #rules

Instance Method Summary collapse

Methods inherited from Value

#check, #configure, #confirmation, #dyn_arg?, #each, #infer_predicates, #initialize, #input, #key, #key?, #new, #node, #predicates, #required, #respond_to?, #root?, #rule, #schema?, #type_map?, #validate, #value, #when

Methods included from StructNode

#node

Methods inherited from DSL

[], #add_check, #add_rule, #initialize, #inspect, #not, #optional, #path, #predicate, #predicate?, #rule_ast, #to_ast, #to_rule, #with

Methods included from Deprecations

format, #logger, #warn

Constructor Details

This class inherits a constructor from Dry::Validation::Schema::Value

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *meth_args) ⇒ Object (private)



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/dry/validation/schema/check.rb', line 21

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

  keys = [path, vals.map(&:path)].reject(&:empty?)

  registry.ensure_valid_predicate(meth, args.size + keys.size, schema_class)
  predicate = predicate(meth, args)

  rule = create_rule([:check, [keys.reverse, predicate]], name)

  add_rule(rule)
  rule
end

Instance Method Details

#classObject



5
6
7
# File 'lib/dry/validation/schema/check.rb', line 5

def class
  Check
end

#schema(other = nil, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/dry/validation/schema/check.rb', line 9

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, [[path], schema.to_ast]]))
end