Module: Card::Set::All::Rename

Extended by:
Card::Set
Defined in:
card/tmpsets/set/mod002-core/all/rename.rb

Overview

Set: All cards (Rename)

Constant Summary

Constants included from Helpers

Helpers::SET_PATTERN_TEST_REGEXP

Constants included from Event::Api

Event::Api::OPTIONS

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Card::Set

reset_modules

Methods included from I18nScope

#mod_name, #scope

Methods included from Loader

#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_modules, #register_set

Methods included from Helpers

#method_missing, #num_set_parts, #pattern_code, #respond_to_missing?, #set_name_parts, #shortname, #underscore

Methods included from Card::Set::AdvancedApi

#attachment, #define_set_from_error, #ensure_set, #setting_opts, #stage_method

Methods included from Format

#before, #format, layout_method_name, #view, view_method_name, view_setting_method_name, wrapper_method_name

Methods included from Inheritance

#include_set, #include_set_formats

Methods included from Basket

#abstract_basket, #add_to_basket, #basket, #unshift_basket

Methods included from Trait

#card_accessor, #card_reader, #card_writer, #require_field

Methods included from Event::Api

#event

Class Method Details

.source_locationObject



7
# File 'card/tmpsets/set/mod002-core/all/rename.rb', line 7

def self.source_location; "/Users/ethan/dev/decko/gem/card/mod/core/set/all/rename.rb"; end

Instance Method Details

#changed_from_simple_to_compound?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'card/tmpsets/set/mod002-core/all/rename.rb', line 33

def changed_from_simple_to_compound?
  name.compound? && name_before_act.to_name.simple?
end

#detect_illegal_compound_namesObject



37
38
39
40
# File 'card/tmpsets/set/mod002-core/all/rename.rb', line 37

def detect_illegal_compound_names
  return unless changed_from_simple_to_compound? && child_ids(:right).present?
  errors.add :name, "illegal name change; existing names end in +#{name_before_act}"
end

#event: cascade_name_changesObject



23
24
25
26
27
28
29
30
31
# File 'card/tmpsets/set/mod002-core/all/rename.rb', line 23

event :cascade_name_changes, :finalize, on: :update, changed: :name do
  each_descendant do |d|
    d.action = :update
    update_referers ? d.update_referers : d.update_referer_references_out
    d.refresh_references_in
    d.refresh_references_out
    d.expire
  end
end

#event: rename_in_trashObject



8
9
10
11
12
13
14
# File 'card/tmpsets/set/mod002-core/all/rename.rb', line 8

event :rename_in_trash, after: :expire_old_name, on: :update do
  existing_card = Card.find_by_key_and_trash name.key, true
  return if !existing_card || existing_card == self
  existing_card.name = existing_card.name + "*trash"
  existing_card.rename_in_trash_without_callbacks
  existing_card.save!
end

#event: validate_renamingObject



16
17
18
19
20
21
# File 'card/tmpsets/set/mod002-core/all/rename.rb', line 16

event :validate_renaming, :validate, on: :update, changed: :name, skip: :allowed do
  return if name_before_act&.to_name == name # just changing to new variant
  errors.add :content, tr(:cannot_change_content) if content_is_changing?
  errors.add :type, tr(:cannot_change_type) if type_is_changing?
  detect_illegal_compound_names
end