Sha256: 52d10c0bf74a3dcd9756bd291f6a1daaf018f485101abc0324acf082b9b2c18a

Contents?: true

Size: 1.12 KB

Versions: 19

Compression:

Stored size: 1.12 KB

Contents

require "edition"

class LicenceEdition < Edition

  field :licence_identifier,  :type => String
  field :licence_short_description, :type => String
  field :licence_overview,  :type => String
  field :will_continue_on, :type => String
  field :continuation_link, :type => String

  GOVSPEAK_FIELDS = [:licence_overview]

  validates :licence_identifier, :presence => true
  validate :licence_identifier_unique
  validates_format_of :continuation_link, :with => URI::regexp(%w(http https)), :allow_blank => true

  @fields_to_clone = [:licence_identifier, :licence_short_description,
                      :licence_overview, :will_continue_on, :continuation_link]

  def whole_body
    [licence_short_description, licence_overview].join("\n\n")
  end

  def indexable_content
    "#{super} #{licence_short_description} #{Govspeak::Document.new(licence_overview).to_text}".strip
  end

  private
  def licence_identifier_unique
    if self.class.without_state('archived').where(:licence_identifier => licence_identifier,
                        :panopticon_id.ne => panopticon_id).any?
      errors.add(:licence_identifier, :taken)
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
govuk_content_models-29.1.2 app/models/licence_edition.rb
govuk_content_models-29.1.1 app/models/licence_edition.rb
govuk_content_models-29.1.0 app/models/licence_edition.rb
govuk_content_models-29.0.1 app/models/licence_edition.rb
govuk_content_models-29.0.0 app/models/licence_edition.rb
govuk_content_models-28.10.0 app/models/licence_edition.rb
govuk_content_models-28.9.0 app/models/licence_edition.rb
govuk_content_models-28.8.0 app/models/licence_edition.rb
govuk_content_models-28.7.1 app/models/licence_edition.rb
govuk_content_models-28.7.0 app/models/licence_edition.rb
govuk_content_models-28.6.2 app/models/licence_edition.rb
govuk_content_models-28.6.1 app/models/licence_edition.rb
govuk_content_models-28.6.0 app/models/licence_edition.rb
govuk_content_models-28.5.0 app/models/licence_edition.rb
govuk_content_models-28.4.0 app/models/licence_edition.rb
govuk_content_models-28.3.0 app/models/licence_edition.rb
govuk_content_models-28.2.0 app/models/licence_edition.rb
govuk_content_models-28.1.0 app/models/licence_edition.rb
govuk_content_models-28.0.1 app/models/licence_edition.rb