Sha256: 00ef4c900668b88dff581ce00fd3874f8a0a6af2f60ee274891a85577482e6ce

Contents?: true

Size: 1.87 KB

Versions: 2

Compression:

Stored size: 1.87 KB

Contents

require "fact_check_address"

class SpecialistDocumentEdition
  include Mongoid::Document
  include Mongoid::Timestamps

  field :document_id,          type: String
  field :version_number,       type: Integer,  default: 1

  field :title,                type: String
  field :created_at,           type: DateTime, default: lambda { Time.zone.now }
  field :slug,                 type: String

  field :summary, type: String
  field :body, type: String
  field :opened_date, type: Date
  field :closed_date, type: Date
  field :case_type, type: String
  field :case_state, type: String
  field :market_sector, type: String
  field :outcome_type, type: String

  field :state, type: String

  state_machine initial: :draft do
    event :publish do
      transition draft: :published
    end

    event :archive do
      transition all => :archived, :unless => :archived?
    end
  end

  GOVSPEAK_FIELDS = [:body]

  def whole_body
    self.body
  end

  scope :draft,               where(state: "draft")
  scope :published,           where(state: "published")
  scope :archived,            where(state: "archived")

  validates :title, presence: true
  validates :summary, presence: true
  validates :body, presence: true
  validates :opened_date, presence: true
  validates :market_sector, presence: true
  validates :case_type, presence: true
  validates :case_state, presence: true
  validates :version_number, presence: true
  validates :document_id, presence: true
  validates_with SafeHtml

  index "document_id"
  index "state"

  def series
    ::SpecialistDocumentEdition.where(document_id: document_id)
  end

  def siblings
    series.excludes(id: id)
  end

  def previous_siblings
    siblings.where(:version_number.lt => version_number)
  end

  def subsequent_siblings
    siblings.where(:version_number.gt => version_number)
  end

  def latest_edition?
    subsequent_siblings.empty?
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
govuk_content_models-8.3.1 app/models/specialist_document_edition.rb
govuk_content_models-8.3.0 app/models/specialist_document_edition.rb