class Erratum::Errors::AttributeLength

Attributes

attribute[RW]
length[RW]
pointer[RW]

Public Class Methods

convert(original_error, overrides = {}) click to toggle source
# File lib/erratum/errors/crud/attribute_length.rb, line 19
def self.convert(original_error, overrides = {})
  case original_error.class.name
  when 'ActiveRecord::ValueTooLong'
    message_info_pattern = /ERROR:  value too long for type character varying\((\d+)\)/
    message_info         = original_error
                             .message
                             .match(message_info_pattern)
                             .captures

    initialization_parameters = {
      attribute: nil,
      pointer:   nil,
      length:    message_info[0],
    }

    new(initialization_parameters.merge(overrides))
  end
end

Public Instance Methods

detail() click to toggle source
# File lib/erratum/errors/crud/attribute_length.rb, line 46
  def detail
    @detail || <<~HEREDOC.chomp.tr("\n", ' ')
      One or more of the attributes you've attempted to set is longer than the
      maximum length of #{length} characters allowed.
    HEREDOC
  end
http_status() click to toggle source
# File lib/erratum/errors/crud/attribute_length.rb, line 38
def http_status
  422
end
source() click to toggle source
Calls superclass method Erratum::Errors::Crud#source
# File lib/erratum/errors/crud/attribute_length.rb, line 53
def source
  super.merge(
    'pointer'   => pointer,
    'parameter' => attribute,
    'length'    => length,
  )
end
title() click to toggle source
# File lib/erratum/errors/crud/attribute_length.rb, line 42
def title
  'Value Too Long'
end