Module: Card::Set::All::Name::ClassMethods

Defined in:
card/tmpsets/set/mod002-core/all/name.rb

Instance Method Summary collapse

Instance Method Details

#generate_alternative_name(name) ⇒ Object



19
20
21
22
23
# File 'card/tmpsets/set/mod002-core/all/name.rb', line 19

def generate_alternative_name name
  uniq_name = "#{name} 1"
  uniq_name.next! while Card.exists?(uniq_name)
  uniq_name
end

#rename!(oldname, newname) ⇒ Object



25
26
27
# File 'card/tmpsets/set/mod002-core/all/name.rb', line 25

def rename! oldname, newname
  Card[oldname].update! name: newname, update_referers: true
end

#uniquify_name(name, rename = :new) ⇒ Object



11
12
13
14
15
16
17
# File 'card/tmpsets/set/mod002-core/all/name.rb', line 11

def uniquify_name name, rename=:new
  return name unless Card.exists? name
  uniq_name = generate_alternative_name name
  return uniq_name unless rename == :old
  rename!(name, uniq_name)
  name
end