4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/models/concerns/mark_as_deleted_with_name.rb', line 4
def mark_as_deleted
max_length = 100_000
if lenval = self.class.validators_on(:name).detect { |v| v.is_a?(ActiveModel::Validations::LengthValidator) }
max_length = lenval.options[:maximum]
end
n = ''
begin
append = " \u2020" + n
deleted_name = name.truncate(max_length - append.length, omission: '') + append
if n.blank?
n = 'A'
else
n.succ!
end
end while self.class.where(name: deleted_name).exists?
update_columns deleted_at: Time.now, name: deleted_name
end
|