Class: ArticleRevision
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- ArticleRevision
- Includes:
- Models::Auditable
- Defined in:
- app/models/article_revision.rb
Overview
== Schema Information
Table name: article_revisions
Database name: primary
id :bigint not null, primary key
change_notes :text
description :text
has_toc :boolean default(FALSE), not null
inline_js :text
meta_description :string
meta_keywords :string
revision_number :integer default(1), not null
solution :text
subject :string not null
title :string
toc_selector :string
created_at :datetime not null
updated_at :datetime not null
article_id :bigint not null
author_id :bigint
Indexes
index_article_revisions_on_article_id_and_revision_number (article_id,revision_number) UNIQUE
index_article_revisions_on_author_id (author_id)
Foreign Keys
fk_rails_... (article_id => articles.id)
Constant Summary collapse
- CONTENT_FIELDS =
Content fields that are stored in revisions
%i[ subject title solution description meta_description meta_keywords inline_js has_toc toc_selector ].freeze
Constants included from Models::Auditable
Models::Auditable::ALWAYS_IGNORED
Instance Attribute Summary collapse
- #revision_number ⇒ Object readonly
- #subject ⇒ Object readonly
Belongs to collapse
Methods included from Models::Auditable
Class Method Summary collapse
-
.chronological ⇒ ActiveRecord::Relation<ArticleRevision>
A relation of ArticleRevisions that are chronological.
-
.reverse_chronological ⇒ ActiveRecord::Relation<ArticleRevision>
A relation of ArticleRevisions that are reverse chronological.
Instance Method Summary collapse
-
#content_attributes ⇒ Object
Returns a hash of content fields for copying to another revision.
-
#current? ⇒ Boolean
Returns true if this is the most recent revision (highest revision_number).
-
#past? ⇒ Boolean
Returns true if this is a past (historical) revision.
Methods included from Models::Auditable
#all_skipped_columns, #audit_reference_data, #should_not_save_version, #stamp_record
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Models::EventPublishable
Instance Attribute Details
#revision_number ⇒ Object (readonly)
40 |
# File 'app/models/article_revision.rb', line 40 validates :revision_number, presence: true, uniqueness: { scope: :article_id } |
#subject ⇒ Object (readonly)
39 |
# File 'app/models/article_revision.rb', line 39 validates :subject, presence: true |
Class Method Details
.chronological ⇒ ActiveRecord::Relation<ArticleRevision>
A relation of ArticleRevisions that are chronological. Active Record Scope
45 |
# File 'app/models/article_revision.rb', line 45 scope :chronological, -> { order(:revision_number) } |
.reverse_chronological ⇒ ActiveRecord::Relation<ArticleRevision>
A relation of ArticleRevisions that are reverse chronological. Active Record Scope
46 |
# File 'app/models/article_revision.rb', line 46 scope :reverse_chronological, -> { order(revision_number: :desc) } |
Instance Method Details
#author ⇒ Employee
37 |
# File 'app/models/article_revision.rb', line 37 belongs_to :author, class_name: 'Employee', optional: true |
#content_attributes ⇒ Object
Returns a hash of content fields for copying to another revision
78 79 80 |
# File 'app/models/article_revision.rb', line 78 def content_attributes CONTENT_FIELDS.index_with { |field| send(field) } end |
#current? ⇒ Boolean
Returns true if this is the most recent revision (highest revision_number).
64 65 66 67 68 69 70 |
# File 'app/models/article_revision.rb', line 64 def current? if article.revisions.loaded? article.revisions.max_by(&:revision_number) == self else !self.class.where(article_id: article_id).where(self.class.arel_table[:revision_number].gt(revision_number)).exists? end end |
#past? ⇒ Boolean
Returns true if this is a past (historical) revision
73 74 75 |
# File 'app/models/article_revision.rb', line 73 def past? !current? end |