Class: Dry::Mutations::Errors::ErrorCompiler
- Inherits:
-
Validation::MessageCompiler
- Object
- Validation::MessageCompiler
- Dry::Mutations::Errors::ErrorCompiler
- Defined in:
- lib/dry/mutations/errors/error_compiler.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#initialize(schema = nil) ⇒ ErrorCompiler
constructor
A new instance of ErrorCompiler.
- #visit_error(node, opts = ::Dry::Validation::EMPTY_HASH) ⇒ Object
Constructor Details
#initialize(schema = nil) ⇒ ErrorCompiler
Returns a new instance of ErrorCompiler.
5 6 7 |
# File 'lib/dry/mutations/errors/error_compiler.rb', line 5 def initialize schema = nil super (schema && schema. || ::Dry::Validation::Schema). end |
Instance Method Details
#visit_error(node, opts = ::Dry::Validation::EMPTY_HASH) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/dry/mutations/errors/error_compiler.rb', line 9 def visit_error(node, opts = ::Dry::Validation::EMPTY_HASH) rule, error = node node_path = Array(opts.fetch(:path, rule)) path = (rule.is_a?(Array) && rule.size > node_path.size ? rule : node_path).compact text = [rule] if text ErrorAtom.new( [*node.first].join('.'), predicate, ::Dry::Validation::Message.new(node, path, text, rule: rule), message: text ) else visit(error, opts.merge(path: path)) end end |