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.
477 478 479 480 481 482 |
# File 'lib/view_model/deserialization_error.rb', line 477 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.
475 476 477 |
# File 'lib/view_model/deserialization_error.rb', line 475 def attribute @attribute end |
#details ⇒ Object (readonly)
Returns the value of attribute details.
475 476 477 |
# File 'lib/view_model/deserialization_error.rb', line 475 def details @details end |
#reason ⇒ Object (readonly)
Returns the value of attribute reason.
475 476 477 |
# File 'lib/view_model/deserialization_error.rb', line 475 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.
494 495 496 497 498 499 500 501 |
# File 'lib/view_model/deserialization_error.rb', line 494 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
484 485 486 |
# File 'lib/view_model/deserialization_error.rb', line 484 def detail "Validation failed: '#{attribute}' #{reason}" end |
#meta ⇒ Object
488 489 490 |
# File 'lib/view_model/deserialization_error.rb', line 488 def super.merge(attribute: attribute, message: reason, details: details) end |