module OldApiResource::ModelErrors::InstanceMethods

Public Instance Methods

errors() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/old_api_resource/model_errors.rb, line 40
def save_with_validations(*args)
  # we want to leave the original intact
  options = args.clone.extract_options!
  
  perform_validation = options.blank? ? true : options[: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?() click to toggle source

This method runs any local validations but not remote ones

Calls superclass method
# File lib/old_api_resource/model_errors.rb, line 73
def valid?
  super
  errors.empty?
end