Sha256: 4a0bc5f70b35d6b0d60a8f20823ef8f38a0ad088285642ba52a19d26b949a765

Contents?: true

Size: 1.46 KB

Versions: 11

Compression:

Stored size: 1.46 KB

Contents

# -*- encoding : utf-8 -*-

def list_fields
  Card.search({ left: name, type_id: Card::MirroredListID }, "list fields")
end

def listed_by_fields
  Card.search({ left: name, type_id: Card::MirrorListID }, "listed by fields")
end

def linker_lists
  Card.search({ type_id: Card::MirroredListID, link_to: name },
              "lists that link to #{name}")
end

def codename_list_exist?
  Card::Codename.exists?(:mirrored_list) && Card::Codename.exists?(:mirror_list)
end

event :trunk_cardtype_of_a_list_relation_changed, :finalize,
      changed: :type, on: :update,
      when: :codename_list_exist? do
  type_key_was = (tk = Card.quick_fetch(type_id_before_last_save)) && tk.key

  list_fields.each do |card|
    card.update_listed_by_cache_for card.item_keys, type_key: type_key_was
    card.update_listed_by_cache_for card.item_keys
  end
  listed_by_fields.each &:update_cached_list
end

event :trunk_name_of_a_list_relation_changed, :finalize,
      changed: :name, on: :update,
      when: :codename_list_exist? do
  list_fields.each do |card|
    card.update_listed_by_cache_for card.item_keys
  end
  listed_by_fields.each &:update_cached_list
end

event :cardtype_of_list_item_changed, :validate,
      changed: :type, on: :save,
      when: :codename_list_exist? do
  linker_lists.each do |card|
    next unless card.item_type_id != type_id
    errors.add(:type,
               "can't be changed because #{name} " \
               "is referenced by list card #{card.name}")
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
card-1.99.6 mod/standard/set/all/list_changes.rb
card-1.99.5 mod/standard/set/all/list_changes.rb
card-1.99.4 mod/standard/set/all/list_changes.rb
card-1.99.3 mod/standard/set/all/list_changes.rb
card-1.99.2 mod/standard/set/all/list_changes.rb
card-1.99.1 mod/standard/set/all/list_changes.rb
card-1.99.0 mod/standard/set/all/list_changes.rb
card-1.98.3 mod/standard/set/all/list_changes.rb
card-1.98.2 mod/standard/set/all/list_changes.rb
card-1.98.1 mod/standard/set/all/list_changes.rb
card-1.98.0 mod/standard/set/all/list_changes.rb