BigW Consortium Gitlab

environment.rb 762 Bytes
Newer Older
1
class Environment < ActiveRecord::Base
2
  belongs_to :project, required: true, validate: true
3 4 5

  has_many :deployments

Z.J. van de Weg committed
6 7
  before_validation :nullify_external_url

8 9
  validates :name,
            presence: true,
10
            uniqueness: { scope: :project_id },
11 12 13
            length: { within: 0..255 },
            format: { with: Gitlab::Regex.environment_name_regex,
                      message: Gitlab::Regex.environment_name_regex_message }
14

15 16
  validates :external_url,
            uniqueness: { scope: :project_id },
Z.J. van de Weg committed
17 18 19
            length: { maximum: 255 },
            allow_nil: true,
            addressable_url: true
20

21 22 23
  def last_deployment
    deployments.last
  end
Z.J. van de Weg committed
24 25 26 27

  def nullify_external_url
    self.external_url = nil if self.external_url.blank?
  end
28
end