class Erratum::Errors::ResourcePersistence

Attributes

attribute[RW]
pointer[RW]
value[RW]

Public Class Methods

convert(original_error, overrides = {}) click to toggle source
# File lib/erratum/errors/crud/resource_persistence.rb, line 19
def self.convert(original_error, overrides = {})
  case original_error.class.name
  when 'ActiveRecord::RecordInvalid',
       'ActiveRecord::RecordNotSaved'

    original_error.record.errors.each_with_object([]) do |(attribute, error), errors|
      initialization_parameters = if attribute == :base
                                    {
                                      attribute: nil,
                                      detail:    error.to_s,
                                      pointer:   '/data/base',
                                      value:     nil,
                                    }
                                  else
                                    {
                                      attribute: attribute.to_s.camelize(:lower),
                                      detail:    "#{attribute.to_s.humanize} #{error}",
                                      pointer:   "/data/attributes/#{attribute}",
                                      value:     original_error
                                                   .record
                                                   .public_send(attribute)
                                                   .to_s,
                                    }
                                  end

      errors << new(initialization_parameters.merge(overrides))
    end
  end
end

Public Instance Methods

detail() click to toggle source
# File lib/erratum/errors/crud/resource_persistence.rb, line 57
  def detail
    @detail || <<~HEREDOC.chomp.tr("\n", ' ')
      One or more of the attributes on the #{resource_name} you attempted to
      #{action} is invalid.
    HEREDOC
  end
http_status() click to toggle source
# File lib/erratum/errors/crud/resource_persistence.rb, line 49
def http_status
  422
end
source() click to toggle source
Calls superclass method Erratum::Errors::Crud#source
# File lib/erratum/errors/crud/resource_persistence.rb, line 64
def source
  super.merge(
    'pointer'   => pointer,
    'parameter' => attribute,
    'value'     => value,
  )
end
title() click to toggle source
# File lib/erratum/errors/crud/resource_persistence.rb, line 53
def title
  'Resource Persistence Error'
end