Class: Graphiti::Util::ValidationResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/graphiti/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

Instance Method Summary collapse

Constructor Details

#initialize(object, deserialized_params) ⇒ ValidationResponse



17
18
19
20
# File 'lib/graphiti/util/validation_response.rb', line 17

def initialize(object, deserialized_params)
  @object = object
  @deserialized_params = deserialized_params
end

Instance Attribute Details

#objectObject (readonly)

the object we are saving



12
13
14
# File 'lib/graphiti/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/graphiti/util/validation_response.rb', line 24

def success?
  all_valid?(object, relationships)
end

#to_aArray



29
30
31
# File 'lib/graphiti/util/validation_response.rb', line 29

def to_a
  [object, success?]
end

#validate!Object



33
34
35
36
37
38
# File 'lib/graphiti/util/validation_response.rb', line 33

def validate!
  unless success?
    raise ::Graphiti::Errors::ValidationError.new(self)
  end
  self
end