Class: Dry::Validation::Rust::Evaluator
- Inherits:
-
Object
- Object
- Dry::Validation::Rust::Evaluator
- Defined in:
- lib/dry/validation/rust/evaluator.rb
Overview
The evaluation context for contract rules.
Inside a rule block, self is an Evaluator instance.
It exposes the validated values, the rule path, error collectors, and
the mutable per-call context.
Instance Attribute Summary collapse
-
#index ⇒ Integer?
readonly
Returns the collection index for a
rule.eachevaluation. -
#values ⇒ Contract::Values
readonly
Returns all validated output available to the rule.
Instance Method Summary collapse
-
#base ⇒ Failures
Returns the failure collector for base-level messages.
-
#base_rule_error? ⇒ Boolean
Returns whether a base-level rule error exists.
-
#key(path = default_path) ⇒ Failures
Returns the failure collector for a path, defaulting to the rule path.
-
#key?(name = value_path) ⇒ Boolean
Returns whether validated output contains a key or path.
-
#rule_error?(path = nil) ⇒ Boolean
Returns whether a rule error exists at a path or the default path.
-
#schema_error?(path) ⇒ Boolean
(also: #error?)
Returns whether the schema has an error at a path.
-
#value ⇒ Object?
Returns the value at the rule's primary path, or nil when absent.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object (private)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
287 288 289 290 291 |
# File 'lib/dry/validation/rust/evaluator.rb', line 287 def method_missing(name, ...) return contract.__send__(name, ...) if contract.respond_to?(name, true) super end |
Instance Attribute Details
#index ⇒ Integer? (readonly)
Returns the collection index for a rule.each evaluation.
58 59 60 |
# File 'lib/dry/validation/rust/evaluator.rb', line 58 def index @index end |
#values ⇒ Contract::Values (readonly)
Returns all validated output available to the rule.
44 45 46 |
# File 'lib/dry/validation/rust/evaluator.rb', line 44 def values @values end |
Instance Method Details
#base ⇒ Failures
Returns the failure collector for base-level messages.
129 130 131 |
# File 'lib/dry/validation/rust/evaluator.rb', line 129 def base @base_failures end |
#base_rule_error? ⇒ Boolean
Returns whether a base-level rule error exists.
201 202 203 |
# File 'lib/dry/validation/rust/evaluator.rb', line 201 def base_rule_error? !base.empty? || result.base_rule_error? end |
#key(path = default_path) ⇒ Failures
Returns the failure collector for a path, defaulting to the rule path.
119 120 121 122 |
# File 'lib/dry/validation/rust/evaluator.rb', line 119 def key(path = default_path) normalized = Path.parse(path) @key_failures[normalized] ||= Failures.new(normalized) end |
#key?(name = value_path) ⇒ Boolean
Returns whether validated output contains a key or path.
160 161 162 |
# File 'lib/dry/validation/rust/evaluator.rb', line 160 def key?(name = value_path) Path.key?(values.data, name) end |
#rule_error?(path = nil) ⇒ Boolean
Returns whether a rule error exists at a path or the default path.
188 189 190 191 192 193 194 |
# File 'lib/dry/validation/rust/evaluator.rb', line 188 def rule_error?(path = nil) if path result.rule_error?(path) else !key(default_path).empty? end end |
#schema_error?(path) ⇒ Boolean Also known as: error?
Returns whether the schema has an error at a path.
170 171 172 |
# File 'lib/dry/validation/rust/evaluator.rb', line 170 def schema_error?(path) result.schema_error?(path) end |