Module: OldApiResource::ModelErrors::InstanceMethods
- Defined in:
- lib/old_api_resource/model_errors.rb
Instance Method Summary collapse
- #errors ⇒ Object
- #load_remote_errors(remote_errors, save_cache = false) ⇒ Object
- #save_with_validations(*args) ⇒ Object
-
#valid? ⇒ Boolean
This method runs any local validations but not remote ones.
Instance Method Details
#errors ⇒ Object
78 79 80 |
# File 'lib/old_api_resource/model_errors.rb', line 78 def errors @errors ||= OldApiResource::Errors.new(self) end |
#load_remote_errors(remote_errors, save_cache = false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/old_api_resource/model_errors.rb', line 59 def load_remote_errors(remote_errors, save_cache = false) error_data = self.class.format.decode(remote_errors.response.body)['errors'] || {} if error_data.is_a?(Hash) self.errors.from_hash(error_data) elsif error_data.is_a?(Array) self.errors.from_array(error_data) else raise Exception.new end rescue Exception raise "Invalid response for invalid object: expected an array or hash got #{remote_errors}" end |
#save_with_validations(*args) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/old_api_resource/model_errors.rb', line 40 def save_with_validations(*args) # we want to leave the original intact = args.clone. perform_validation = .blank? ? true : [:validate] @remote_errors = nil if perform_validation && valid? || !perform_validation save_without_validations(*args) true else false end rescue OldApiResource::UnprocessableEntity => error @remote_errors = error load_remote_errors(@remote_errors, true) false end |
#valid? ⇒ Boolean
This method runs any local validations but not remote ones
73 74 75 76 |
# File 'lib/old_api_resource/model_errors.rb', line 73 def valid? super errors.empty? end |