Class: Dry::Validation::Rust::Schema::Result
- Inherits:
-
Data
- Object
- Data
- Dry::Validation::Rust::Schema::Result
- Defined in:
- lib/dry/validation/rust/schema/result.rb
Instance Attribute Summary collapse
-
#error_prefixes ⇒ Object
readonly
Returns the value of attribute error_prefixes.
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
-
#output ⇒ Object
(also: #to_h)
readonly
Returns the value of attribute output.
Class Method Summary collapse
- .build ⇒ Object
-
.new(output = nil, messages = nil, **kwargs) ⇒ Result
Creates a structural validation result and caches its schema-error path index.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #error?(spec) ⇒ Boolean
- #errors(options = {}) ⇒ Object
- #failure? ⇒ Boolean
- #key?(key) ⇒ Boolean
- #success? ⇒ Boolean
Instance Attribute Details
#error_prefixes ⇒ Object (readonly)
Returns the value of attribute error_prefixes
7 8 9 |
# File 'lib/dry/validation/rust/schema/result.rb', line 7 def error_prefixes @error_prefixes end |
#messages ⇒ Object (readonly)
Returns the value of attribute messages
7 8 9 |
# File 'lib/dry/validation/rust/schema/result.rb', line 7 def @messages end |
#output ⇒ Object (readonly) Also known as: to_h
Returns the value of attribute output
7 8 9 |
# File 'lib/dry/validation/rust/schema/result.rb', line 7 def output @output end |
Class Method Details
.build ⇒ Object
9 |
# File 'lib/dry/validation/rust/schema/result.rb', line 9 alias_method :build, :new |
.new(output = nil, messages = nil, **kwargs) ⇒ Result
Creates a structural validation result and caches its schema-error path index.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dry/validation/rust/schema/result.rb', line 17 def new(output = nil, = nil, **kwargs) unknown = kwargs.keys - %i[output messages] unless unknown.empty? raise ArgumentError, "unknown keyword#{'s' if unknown.length > 1}: #{unknown.map(&:inspect).join(', ')}" end output = kwargs.fetch(:output) if kwargs.key?(:output) = kwargs.fetch(:messages) if kwargs.key?(:messages) prefixes = PathTrie.new .each { || prefixes.add(.path) } build(output, , prefixes.freeze) end |
Instance Method Details
#[](key) ⇒ Object
56 57 58 |
# File 'lib/dry/validation/rust/schema/result.rb', line 56 def [](key) output[key] end |
#error?(spec) ⇒ Boolean
51 52 53 54 |
# File 'lib/dry/validation/rust/schema/result.rb', line 51 def error?(spec) path = Path.parse(spec) .any? { || Path.prefix?(.path, path) } end |
#errors(options = {}) ⇒ Object
47 48 49 |
# File 'lib/dry/validation/rust/schema/result.rb', line 47 def errors( = {}) MessageSet.new(, ).with() end |
#failure? ⇒ Boolean
43 44 45 |
# File 'lib/dry/validation/rust/schema/result.rb', line 43 def failure? !success? end |
#key?(key) ⇒ Boolean
60 61 62 |
# File 'lib/dry/validation/rust/schema/result.rb', line 60 def key?(key) output.key?(key) end |
#success? ⇒ Boolean
39 40 41 |
# File 'lib/dry/validation/rust/schema/result.rb', line 39 def success? .empty? end |