Module: Models::CrossLinkable

Extended by:
ActiveSupport::Concern
Included in:
Article, Item, Showcase, Video
Defined in:
app/concerns/models/cross_linkable.rb

Overview

ActiveSupport::Concern mixin: cross linkable.

Gives a content model its editorial cross-links (see ContentLink).
ContentLink stores endpoints as exclusive-arc FK columns — one per linkable
base class — so the associations here resolve the including model's
base class to its arc column at include time (Video -> DigitalAsset ->
source_digital_asset_id; Post inherits Article's -> source_article_id).

Has many collapse

Instance Method Summary collapse

Instance Method Details

#case_evidenceArray

Returns linked case-evidence records.

Returns:

  • (Array)

    linked case-evidence records



52
# File 'app/concerns/models/cross_linkable.rb', line 52

def case_evidence       = linked_content('case_evidence')

Number of outbound cross-links on this record.

Returns:

  • (Integer)


56
57
58
# File 'app/concerns/models/cross_linkable.rb', line 56

def content_links_count
  outbound_content_links.size
end

Cross-links from other content that point at this record.

Returns:

  • (ActiveRecord::Associations::CollectionProxy<ContentLink>)


26
27
28
29
# File 'app/concerns/models/cross_linkable.rb', line 26

has_many :inbound_content_links,  class_name: 'ContentLink',
foreign_key: :"#{target_arc}_id",
inverse_of: target_arc,
dependent: :destroy

#linked_articlesArray

Returns linked articles.

Returns:

  • (Array)

    linked articles



42
43
# File 'app/concerns/models/cross_linkable.rb', line 42

def linked_articles     = linked_content('related_article')
# @return [Array] linked FAQs

#linked_content(link_type) ⇒ Array

Targets of this record's outbound cross-links of the given type.

Parameters:

  • link_type (String)

    ContentLink link type (e.g. 'related_post')

Returns:

  • (Array)

    the linked target records, in editorial order



35
36
37
# File 'app/concerns/models/cross_linkable.rb', line 35

def linked_content(link_type)
  outbound_content_links.of_type(link_type).ordered.with_targets.map(&:target)
end

#linked_faqsArray

Returns linked FAQs.

Returns:

  • (Array)

    linked FAQs



44
45
# File 'app/concerns/models/cross_linkable.rb', line 44

def linked_faqs         = linked_content('related_faq')
# @return [Array] linked videos

#linked_postsArray

Returns linked posts.

Returns:

  • (Array)

    linked posts



40
41
# File 'app/concerns/models/cross_linkable.rb', line 40

def linked_posts        = linked_content('related_post')
# @return [Array] linked articles

#linked_publicationsArray

Returns linked publications.

Returns:

  • (Array)

    linked publications



50
51
# File 'app/concerns/models/cross_linkable.rb', line 50

def linked_publications = linked_content('related_publication')
# @return [Array] linked case-evidence records

#linked_showcasesArray

Returns linked showcases.

Returns:

  • (Array)

    linked showcases



48
49
# File 'app/concerns/models/cross_linkable.rb', line 48

def linked_showcases    = linked_content('related_showcase')
# @return [Array] linked publications

#linked_videosArray

Returns linked videos.

Returns:

  • (Array)

    linked videos



46
47
# File 'app/concerns/models/cross_linkable.rb', line 46

def linked_videos       = linked_content('related_video')
# @return [Array] linked showcases

dependent: :destroy is belt-and-braces — the arc FKs CASCADE at the DB
level, which also covers deletes that bypass callbacks.

Returns:

See Also:



19
20
21
22
# File 'app/concerns/models/cross_linkable.rb', line 19

has_many :outbound_content_links, class_name: 'ContentLink',
foreign_key: :"#{source_arc}_id",
inverse_of: source_arc,
dependent: :destroy