Module: Card::Set::All::References
- Extended by:
- Card::Set
- Defined in:
- tmpsets/set/mod001-01_core/all/references.rb
Constant Summary collapse
- PARTIAL_REF_CODE =
~~~~~~~~~~~ above autogenerated; below pulled from /Users/ethan/dev/wagn/gem/card/mod/01_core/set/all/references.rb ~~~~~~~~~~~
'P'
Instance Method Summary collapse
- #create_reference_to(chunk) ⇒ Object
- #extended_referencers ⇒ Object
- #includees ⇒ Object
- #includers ⇒ Object
- #name_referencers(link_name = nil) ⇒ Object
- #referees ⇒ Object
- #referencers ⇒ Object
-
#replace_references(old_name, new_name) ⇒ Object
replace references in card content.
-
#update_references(rendered_content = nil) ⇒ Object
update entries in reference table.
Methods included from Loader
#clean_empty_module_from_hash, #clean_empty_modules, #extended, #process_base_module_list, #process_base_modules, #register_set, #write_tmp_file
Methods included from Helpers
#abstract_set?, #all_set?, #attachment, #ensure_set, #include_set, #include_set_formats, #shortname, #stage_method
Methods included from Format
#all_set_format_mod!, #applicable_format?, #define_on_format, #each_format, #format, #register_set_format, #view
Methods included from Trait
#card_accessor, #card_reader, #card_writer
Methods included from Event
Instance Method Details
#create_reference_to(chunk) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 43 def create_reference_to chunk referee_name = chunk.referee_name return false unless referee_name # eg no commented nest referee_name.piece_names.each do |name| next if name.key == key # don't create self reference # reference types: # L = link # I = inclusion # P = partial (i.e. the name is part of a compound name that is # referenced by a link or inclusion) # The partial type is needed to keep track of references of virtual cards. # For example a link [[A+*self]] won't make it to the reference table # because A+*self is virtual and doesn't have an id but when A's name is # changed we have to find and update that link. ref_type = name != referee_name ? PARTIAL_REF_CODE : chunk.reference_code Card::Reference.create!( referer_id: id, referee_id: Card.fetch_id(name), referee_key: name.key, ref_type: ref_type, present: 1 ) end end |
#extended_referencers ⇒ Object
12 13 14 15 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 12 def extended_referencers # FIXME: .. we really just need a number here. (descendants + [self]).map(&:referencers).flatten.uniq end |
#includees ⇒ Object
84 85 86 87 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 84 def includees references_to.where(ref_type: 'I') .map { |ref| Card.fetch ref.referee_key, new: {} } end |
#includers ⇒ Object
75 76 77 78 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 75 def includers references_from.where(ref_type: 'I') .map(&:referer_id).map(&Card.method(:fetch)).compact end |
#name_referencers(link_name = nil) ⇒ Object
7 8 9 10 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 7 def name_referencers link_name=nil link_name = link_name.nil? ? key : link_name.to_name.key Card.joins(:references_to).where card_references: { referee_key: link_name } end |
#referees ⇒ Object
80 81 82 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 80 def referees references_to.map { |ref| Card.fetch ref.referee_key, new: {} } end |
#referencers ⇒ Object
71 72 73 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 71 def referencers references_from.map(&:referer_id).map(&Card.method(:fetch)).compact end |
#replace_references(old_name, new_name) ⇒ Object
replace references in card content
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 18 def replace_references old_name, new_name obj_content = Card::Content.new raw_content, self obj_content.find_chunks(Card::Chunk::Reference).select do |chunk| next unless (old_ref_name = chunk.referee_name) next unless (new_ref_name = old_ref_name.replace_part old_name, new_name) chunk.referee_name = chunk.replace_reference old_name, new_name old_references = Card::Reference.where(referee_key: old_ref_name.key) old_references.update_all referee_key: new_ref_name.key end obj_content.to_s end |
#update_references(rendered_content = nil) ⇒ Object
update entries in reference table
32 33 34 35 36 37 38 39 40 41 |
# File 'tmpsets/set/mod001-01_core/all/references.rb', line 32 def update_references rendered_content=nil raise 'update references should not be called on new cards' if id.nil? Card::Reference.delete_all_from self unless self.new_card? rendered_content ||= Card::Content.new raw_content, self rendered_content.find_chunks(Card::Chunk::Reference).each do |chunk| create_reference_to chunk end end |