Module: Card::Set::All::ReferenceEvents

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

Overview

test for updating referer content

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



8
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 8

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

Instance Method Details

#event: clear_referencesObject

clean up reference table when card is deleted



45
46
47
48
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 45

event :clear_references, :finalize, on: :delete do
  delete_references_out
  Reference.unmap_referees id
end

#event: prepare_referer_updateObject



9
10
11
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 9

event :prepare_referer_update, :validate, on: :update, changed: :name do
  self.update_referers = ![nil, false, "false"].member?(update_referers)
end

#event: refresh_references_inObject

when name changes, update references to card



34
35
36
37
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 34

event :refresh_references_in, :finalize, changed: :name, on: :save do
  Reference.unmap_referees id if action == :update && !update_referers
  Reference.map_referees key, id
end

#event: refresh_references_outObject

when content changes, update references to other cards



40
41
42
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 40

event :refresh_references_out, :finalize, on: :save, changed: :content do
  update_references_out
end

#event: update_referer_contentObject

on rename, update names in cards that refer to self by name (as directed)



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

event :update_referer_content, :finalize, on: :update, when: :update_referers do
  referers.each do |card|
    next if card.structure

    card.skip_event! :validate_renaming, :check_permissions
    card.content = card.replace_references name_before_act, name
    attach_subcard card
  end
end

#event: update_referer_references_outObject

on rename, when NOT updating referer content, update references to ensure that partial references are correctly tracked eg. A links to X+Y. if X+Y is renamed and we’re not updating the link in A, then we need to be sure that A has a partial reference



28
29
30
31
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 28

event :update_referer_references_out, :finalize,
      changed: :name, on: :update, when: :not_update_referers do
  referers.map(&:update_references_out)
end

#replace_references(old_name, new_name) ⇒ Object

replace references in card content



51
52
53
54
55
56
57
# File 'card/tmpsets/set/mod002-core/all/reference_events.rb', line 51

def replace_references old_name, new_name
  cont = content_object
  cont.find_chunks(:Reference).each do |chunk|
    next unless replace_reference chunk, old_name, new_name
  end
  cont.to_s
end