Exception: ViewModel::DeserializationError::Validation
- Inherits:
-
ViewModel::DeserializationError
- Object
- StandardError
- AbstractError
- AbstractErrorWithBlame
- ViewModel::DeserializationError
- ViewModel::DeserializationError::Validation
- Defined in:
- lib/view_model/deserialization_error.rb
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#reason ⇒ Object
readonly
Returns the value of attribute reason.
Attributes inherited from AbstractErrorWithBlame
Class Method Summary collapse
-
.from_active_model(errors, node) ⇒ Object
Return Validation errors for each error in the the provided ActiveModel::Errors, wrapped in a Collection if necessary.
Instance Method Summary collapse
- #detail ⇒ Object
-
#initialize(attribute, reason, details, node) ⇒ Validation
constructor
A new instance of Validation.
- #meta ⇒ Object
Methods inherited from ViewModel::DeserializationError
Methods inherited from AbstractError
#aggregation?, #causes, #code, #exception, #status, #title, #to_s, #view
Constructor Details
#initialize(attribute, reason, details, node) ⇒ Validation
Returns a new instance of Validation.
460 461 462 463 464 465 |
# File 'lib/view_model/deserialization_error.rb', line 460 def initialize(attribute, reason, details, node) @attribute = attribute @reason = reason @details = details super([node]) end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
458 459 460 |
# File 'lib/view_model/deserialization_error.rb', line 458 def attribute @attribute end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
458 459 460 |
# File 'lib/view_model/deserialization_error.rb', line 458 def details @details end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
458 459 460 |
# File 'lib/view_model/deserialization_error.rb', line 458 def reason @reason end |
Class Method Details
.from_active_model(errors, node) ⇒ Object
Return Validation errors for each error in the the provided ActiveModel::Errors, wrapped in a Collection if necessary.
477 478 479 480 481 482 483 484 |
# File 'lib/view_model/deserialization_error.rb', line 477 def self.from_active_model(errors, node) causes = errors..each_key.flat_map do |attr| errors.[attr].zip(errors.details[attr]).map do |, details| self.new(attr.to_s, , details, node) end end Collection.for_errors(causes) end |
Instance Method Details
#detail ⇒ Object
467 468 469 |
# File 'lib/view_model/deserialization_error.rb', line 467 def detail "Validation failed: '#{attribute}' #{reason}" end |
#meta ⇒ Object
471 472 473 |
# File 'lib/view_model/deserialization_error.rb', line 471 def super.merge(attribute: attribute, message: reason, details: details) end |