Exception: Familia::RecordExistsError

Inherits:
NonUniqueKey show all
Defined in:
lib/familia/errors.rb

Overview

Raised when attempting to create an object that already exists in the database

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, existing_id: nil) ⇒ RecordExistsError

Returns a new instance of RecordExistsError.



195
196
197
198
199
# File 'lib/familia/errors.rb', line 195

def initialize(key, existing_id: nil)
  @existing_id = existing_id
  @key = key
  super(key)
end

Instance Attribute Details

#existing_idObject (readonly)

Returns the value of attribute existing_id.



193
194
195
# File 'lib/familia/errors.rb', line 193

def existing_id
  @existing_id
end

#keyObject (readonly)

Returns the value of attribute key.



193
194
195
# File 'lib/familia/errors.rb', line 193

def key
  @key
end

Instance Method Details

#messageObject



201
202
203
204
205
206
207
208
209
210
# File 'lib/familia/errors.rb', line 201

def message
  msg = "Key already exists: #{key}"
  begin
    msg << " (existing_id=#{existing_id})" unless existing_id.nil?
  rescue StandardError
    # existing_id may not support nil?/to_s (e.g. a Redis::Future captured
    # inside a MULTI); a diagnostic message must never raise itself.
  end
  msg
end