Module: Card::Reference::All
- Included in:
- Card
- Defined in:
- lib/card/reference/all.rb
Constant Summary collapse
- PARTIAL_REF_CODE =
Cards can refer to other cards in their content, eg via links and nests. The card that refers is the “referer”, the card that is referred to is the “referee”. The reference itself has its own class (Card::Reference), which handles id-based reference tracking.
"P".freeze
Instance Method Summary collapse
-
#create_references_out ⇒ Object
interpret references from this card’s content and insert entries in reference table.
-
#name_referers ⇒ Object
cards that refer to self by name (finds cards not yet linked by id).
-
#nestees ⇒ Object
cards that self includes.
-
#nesters ⇒ Object
cards that include self.
-
#referees ⇒ Object
cards that self refers to.
- #referees_from_references(references) ⇒ Object
- #referer_cards_from_references(references) ⇒ Object
-
#referers ⇒ Object
cards that refer to self.
-
#swap_names(old_name, new_name) ⇒ Object
replace references in card content.
-
#update_references_out ⇒ Object
delete old references from this card’s content, create new ones.
Instance Method Details
#create_references_out ⇒ Object
interpret references from this card’s content and insert entries in reference table
55 56 57 58 59 60 61 62 63 |
# File 'lib/card/reference/all.rb', line 55 def create_references_out ref_hash = {} each_reference_out do |referee_name, ref_type| interpret_reference ref_hash, referee_name, ref_type end return if ref_hash.empty? Reference.mass_insert reference_values_array(ref_hash) end |
#name_referers ⇒ Object
cards that refer to self by name (finds cards not yet linked by id)
43 44 45 |
# File 'lib/card/reference/all.rb', line 43 def name_referers Card.joins(:references_out).where card_references: { referee_key: key } end |
#nestees ⇒ Object
cards that self includes
33 34 35 |
# File 'lib/card/reference/all.rb', line 33 def nestees referees_from_references references_out.where(ref_type: "I") end |
#nesters ⇒ Object
cards that include self
19 20 21 |
# File 'lib/card/reference/all.rb', line 19 def nesters referer_cards_from_references references_in.where(ref_type: "I") end |
#referees ⇒ Object
cards that self refers to
28 29 30 |
# File 'lib/card/reference/all.rb', line 28 def referees referees_from_references references_out end |
#referees_from_references(references) ⇒ Object
37 38 39 |
# File 'lib/card/reference/all.rb', line 37 def referees_from_references references references.map(&:referee_key).uniq.map { |key| Card.fetch key, new: {} } end |
#referer_cards_from_references(references) ⇒ Object
23 24 25 |
# File 'lib/card/reference/all.rb', line 23 def referer_cards_from_references references references.map(&:referer_id).uniq.map(&:card).compact end |
#referers ⇒ Object
cards that refer to self
14 15 16 |
# File 'lib/card/reference/all.rb', line 14 def referers referer_cards_from_references references_in end |
#swap_names(old_name, new_name) ⇒ Object
replace references in card content
66 67 68 69 70 71 72 |
# File 'lib/card/reference/all.rb', line 66 def swap_names old_name, new_name cont = content_object cont.find_chunks(:Reference).each do |chunk| chunk.swap_name old_name, new_name end cont.to_s end |
#update_references_out ⇒ Object
delete old references from this card’s content, create new ones
48 49 50 51 |
# File 'lib/card/reference/all.rb', line 48 def update_references_out delete_references_out create_references_out end |