Class: ArticleRevision

Inherits:
ApplicationRecord show all
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

Belongs to collapse

Methods included from Models::Auditable

#creator, #updater

Class Method Summary collapse

Instance Method Summary collapse

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

#publish_event

Instance Attribute Details

#revision_numberObject (readonly)



40
# File 'app/models/article_revision.rb', line 40

validates :revision_number, presence: true, uniqueness: { scope: :article_id }

#subjectObject (readonly)



39
# File 'app/models/article_revision.rb', line 39

validates :subject, presence: true

Class Method Details

.chronologicalActiveRecord::Relation<ArticleRevision>

A relation of ArticleRevisions that are chronological. Active Record Scope

Returns:

See Also:



45
# File 'app/models/article_revision.rb', line 45

scope :chronological, -> { order(:revision_number) }

.reverse_chronologicalActiveRecord::Relation<ArticleRevision>

A relation of ArticleRevisions that are reverse chronological. Active Record Scope

Returns:

See Also:



46
# File 'app/models/article_revision.rb', line 46

scope :reverse_chronological, -> { order(revision_number: :desc) }

Instance Method Details

#articleArticle

Returns:

See Also:



36
# File 'app/models/article_revision.rb', line 36

belongs_to :article

#authorEmployee

Returns:

See Also:



37
# File 'app/models/article_revision.rb', line 37

belongs_to :author, class_name: 'Employee', optional: true

#content_attributesObject

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).

Returns:

  • (Boolean)


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

Returns:

  • (Boolean)


73
74
75
# File 'app/models/article_revision.rb', line 73

def past?
  !current?
end