Sha256: 2d7f75407b33cc3856d63faca7212c5e063c3fbcdf2ac1d068852bc765a7973b

Contents?: true

Size: 815 Bytes

Versions: 35

Compression:

Stored size: 815 Bytes

Contents

class Downtime
  include Mongoid::Document
  include Mongoid::Timestamps

  field :message, type: String
  field :start_time, type: DateTime
  field :end_time, type: DateTime

  belongs_to :artefact

  validates_presence_of :message, :start_time, :end_time, :artefact
  validate :end_time_is_in_future, on: :create
  validate :start_time_precedes_end_time

  def self.for(artefact)
    where(artefact_id: artefact.id).first
  end

  def publicise?
    Time.zone.now.between?(start_time.yesterday.at_midnight, end_time)
  end

  private

  def end_time_is_in_future
    errors.add(:end_time, "must be in the future") if end_time && ! end_time.future?
  end

  def start_time_precedes_end_time
    errors.add(:start_time, "must be earlier than end time") if start_time && end_time && start_time >= end_time
  end
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
govuk_content_models-43.0.0 app/models/downtime.rb
govuk_content_models-42.1.0 app/models/downtime.rb
govuk_content_models-42.0.1 app/models/downtime.rb
govuk_content_models-42.0.0 app/models/downtime.rb
govuk_content_models-41.1.1 app/models/downtime.rb
govuk_content_models-41.1.0 app/models/downtime.rb
govuk_content_models-41.0.0 app/models/downtime.rb
govuk_content_models-40.0.0 app/models/downtime.rb
govuk_content_models-39.0.0 app/models/downtime.rb
govuk_content_models-38.0.0 app/models/downtime.rb
govuk_content_models-37.0.0 app/models/downtime.rb
govuk_content_models-36.0.0 app/models/downtime.rb
govuk_content_models-35.0.1 app/models/downtime.rb
govuk_content_models-35.0.0 app/models/downtime.rb
govuk_content_models-34.0.0 app/models/downtime.rb
govuk_content_models-33.0.0 app/models/downtime.rb
govuk_content_models-32.3.1 app/models/downtime.rb
govuk_content_models-32.3.0 app/models/downtime.rb
govuk_content_models-32.2.0 app/models/downtime.rb
govuk_content_models-32.1.0 app/models/downtime.rb