Class: Dry::Validation::Schema::Key
- Inherits:
-
DSL
- Object
- DSL
- Dry::Validation::Schema::Key
show all
- Defined in:
- lib/dry/validation/schema/key.rb
Instance Attribute Summary collapse
Attributes inherited from DSL
#checks, #name, #options, #registry, #rules
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from DSL
[], #add_check, #add_rule, #initialize, #inspect, #not, #optional, #path, #predicate, #predicate?, #rule_ast, #to_rule, #with
format, #logger, #warn
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/dry/validation/schema/key.rb', line 55
def method_missing(meth, *args, &block)
registry.ensure_valid_predicate(meth, args)
predicate = predicate(meth, args)
if block
val = value.instance_eval(&block)
add_rule(create_rule([:and, [predicate, val.to_ast]]))
else
rule = create_rule([type, [name, predicate]])
add_rule(rule)
rule
end
end
|
Instance Attribute Details
#parent ⇒ Object
Returns the value of attribute parent.
7
8
9
|
# File 'lib/dry/validation/schema/key.rb', line 7
def parent
@parent
end
|
Class Method Details
.type ⇒ Object
9
10
11
|
# File 'lib/dry/validation/schema/key.rb', line 9
def self.type
:key
end
|
Instance Method Details
#class ⇒ Object
13
14
15
|
# File 'lib/dry/validation/schema/key.rb', line 13
def class
Key
end
|
#each(*predicates, &block) ⇒ Object
25
26
27
|
# File 'lib/dry/validation/schema/key.rb', line 25
def each(*predicates, &block)
create_rule([type, [name, value.each(*predicates, &block).to_ast]])
end
|
#hash?(&block) ⇒ Boolean
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/dry/validation/schema/key.rb', line 33
def hash?(&block)
predicate = predicate(:hash?)
if block
val = value.instance_eval(&block)
rule = create_rule(predicate)
.and(create_rule([type, [name, val.to_ast]]))
add_rule(rule)
rule
else
add_rule(create_rule(predicate))
end
end
|
#schema(other = nil, &block) ⇒ Object
29
30
31
|
# File 'lib/dry/validation/schema/key.rb', line 29
def schema(other = nil, &block)
create_rule([type, [name, value.schema(other, &block).to_ast]])
end
|
#to_ast ⇒ Object
21
22
23
|
# File 'lib/dry/validation/schema/key.rb', line 21
def to_ast
[type, [name, super]]
end
|
#type ⇒ Object
17
18
19
|
# File 'lib/dry/validation/schema/key.rb', line 17
def type
self.class.type
end
|
#value ⇒ Object
49
50
51
|
# File 'lib/dry/validation/schema/key.rb', line 49
def value
Value[name, registry: registry]
end
|