class Dalton::UniqueConflict

Constants

MESSAGE_RE

TODO: [jneen] this is terrible, but error handling is not implemented at the moment. eventually all this data should be accessible via (ex-data e).

Attributes

attribute[R]
existing_id[R]
message[R]
new_id[R]
value[R]

Public Class Methods

new(opts={}) click to toggle source
# File lib/dalton/exception.rb, line 21
def initialize(opts={})
  @attribute = opts.fetch(:attribute)
  @value = opts.fetch(:value)
  @existing_id = opts.fetch(:existing_id)
  @new_id = opts.fetch(:new_id)
  @message = "Unique conflict: tried to assign duplicate #@attribute to #@new_id, already held by #@existing_id. value: #@value"
end
parse(message) click to toggle source
# File lib/dalton/exception.rb, line 8
def self.parse(message)
  message =~ MESSAGE_RE
  raise ArgumentError, "invalid format: #{message.inspect}" unless $~
  new(
    attribute: $1.to_sym,
    value: $2,
    existing_id: Integer($3),
    new_id: Integer($4),
  )
end

Public Instance Methods

inspect() click to toggle source
# File lib/dalton/exception.rb, line 33
def inspect
  "#<#{self.class.name}: @attribute=#@attribute @value=#@value @existing_id=#@existing_id @new_id=#@new_id>"
end
to_s() click to toggle source
# File lib/dalton/exception.rb, line 29
def to_s
  "#{self.class.name}: #@message"
end