Class: Dry::Mutations::Errors::ErrorAtom
- Inherits:
-
Mutations::ErrorAtom
- Object
- Mutations::ErrorAtom
- Dry::Mutations::Errors::ErrorAtom
- Defined in:
- lib/dry/mutations/errors/error_atom.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#dry_message ⇒ Object
readonly
Returns the value of attribute dry_message.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(key, error_symbol, dry_message, options = {}) ⇒ ErrorAtom
constructor
A new instance of ErrorAtom.
Constructor Details
#initialize(key, error_symbol, dry_message, options = {}) ⇒ ErrorAtom
Returns a new instance of ErrorAtom.
13 14 15 16 |
# File 'lib/dry/mutations/errors/error_atom.rb', line 13 def initialize(key, error_symbol, , = {}) super key, Utils::DRY_TO_MUTATIONS[error_symbol] || error_symbol, @dry_message = end |
Instance Attribute Details
#dry_message ⇒ Object (readonly)
Returns the value of attribute dry_message.
11 12 13 |
# File 'lib/dry/mutations/errors/error_atom.rb', line 11 def @dry_message end |
Class Method Details
.patch_message_set(set) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/dry/mutations/errors/error_atom.rb', line 18 def self.(set) return nil if set.empty? fail TypeError, "Expected: ::Dry::Validation::MessageSet; got: #{set.class}" unless set.is_a?(::Dry::Validation::MessageSet) set.map.with_index.with_object(::Mutations::ErrorHash.new) do |(msg, idx), memo| # key = msg.path.join('.') last = msg.path.pop tail = msg.path.inject(memo) { |acc, curr| acc[curr.to_s] ||= ::Mutations::ErrorHash.new } tail[last] = case tail[last] when ErrorAtom then ::Mutations::ErrorArray.new << tail[last.to_s] when NilClass then ::Mutations::ErrorArray.new when ::Mutations::ErrorArray then tail[last.to_s] end key = msg.respond_to?(:predicate) ? msg.predicate : last text = msg.respond_to?(:text) ? msg.text : msg.to_s tail[last.to_s] << new(last, key, msg, message: text, index: idx) # memo[key] = new(key, msg.predicate, msg, message: msg.text, index: idx) end end |