Module: Models::CrossLinkable
- Extended by:
- ActiveSupport::Concern
- 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
-
#inbound_content_links ⇒ ActiveRecord::Associations::CollectionProxy<ContentLink>
Cross-links from other content that point at this record.
-
#outbound_content_links ⇒ ActiveRecord::Relation<ContentLink>
dependent: :destroy is belt-and-braces — the arc FKs CASCADE at the DB level, which also covers deletes that bypass callbacks.
Instance Method Summary collapse
-
#case_evidence ⇒ Array
Linked case-evidence records.
-
#content_links_count ⇒ Integer
Number of outbound cross-links on this record.
-
#linked_articles ⇒ Array
Linked articles.
-
#linked_content(link_type) ⇒ Array
Targets of this record's outbound cross-links of the given type.
-
#linked_faqs ⇒ Array
Linked FAQs.
-
#linked_posts ⇒ Array
Linked posts.
-
#linked_publications ⇒ Array
Linked publications.
-
#linked_showcases ⇒ Array
Linked showcases.
-
#linked_videos ⇒ Array
Linked videos.
Instance Method Details
#case_evidence ⇒ Array
Returns linked case-evidence records.
52 |
# File 'app/concerns/models/cross_linkable.rb', line 52 def case_evidence = linked_content('case_evidence') |
#content_links_count ⇒ Integer
Number of outbound cross-links on this record.
56 57 58 |
# File 'app/concerns/models/cross_linkable.rb', line 56 def content_links_count outbound_content_links.size end |
#inbound_content_links ⇒ ActiveRecord::Associations::CollectionProxy<ContentLink>
Cross-links from other content that point at this record.
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_articles ⇒ Array
Returns 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.
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_faqs ⇒ Array
Returns 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_posts ⇒ Array
Returns 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_publications ⇒ Array
Returns 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_showcases ⇒ Array
Returns 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_videos ⇒ Array
Returns linked videos.
46 47 |
# File 'app/concerns/models/cross_linkable.rb', line 46 def linked_videos = linked_content('related_video') # @return [Array] linked showcases |
#outbound_content_links ⇒ ActiveRecord::Relation<ContentLink>
dependent: :destroy is belt-and-braces — the arc FKs CASCADE at the DB
level, which also covers deletes that bypass callbacks.
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 |