Class: JsonapiCompliable::Util::ValidationResponse
- Inherits:
-
Object
- Object
- JsonapiCompliable::Util::ValidationResponse
- Defined in:
- lib/jsonapi_compliable/util/validation_response.rb
Overview
We need to know two things in the response of a persistence call:
* The model we just tried to persist
* Was the persistence successful?
This object wraps those bits of data. The call is considered unsuccessful when it adheres to the ActiveModel#errors interface, and #errors is not blank. In other words, it is not successful if there were validation errors.
Instance Attribute Summary collapse
-
#object ⇒ Object
readonly
the object we are saving.
Instance Method Summary collapse
-
#initialize(object, deserialized_params) ⇒ ValidationResponse
constructor
A new instance of ValidationResponse.
-
#success? ⇒ Boolean
Check to ensure no validation errors.
-
#to_a ⇒ Array
The object and success state.
Constructor Details
#initialize(object, deserialized_params) ⇒ ValidationResponse
Returns a new instance of ValidationResponse
17 18 19 20 |
# File 'lib/jsonapi_compliable/util/validation_response.rb', line 17 def initialize(object, deserialized_params) @object = object @deserialized_params = deserialized_params end |
Instance Attribute Details
#object ⇒ Object (readonly)
the object we are saving
12 13 14 |
# File 'lib/jsonapi_compliable/util/validation_response.rb', line 12 def object @object end |
Instance Method Details
#success? ⇒ Boolean
Check to ensure no validation errors.
24 25 26 |
# File 'lib/jsonapi_compliable/util/validation_response.rb', line 24 def success? all_valid?(object, @deserialized_params.relationships) end |
#to_a ⇒ Array
Returns the object and success state
29 30 31 |
# File 'lib/jsonapi_compliable/util/validation_response.rb', line 29 def to_a [object, success?] end |