gitlab-org--gitlab-foss/app/models/releases/link.rb
Thong Kuah d119d3d1b2 Align UrlValidator to validate_url gem implementation.
Renamed UrlValidator to AddressableUrlValidator to avoid 'url:' naming collision with ActiveModel::Validations::UrlValidator in 'validates' statement.
Make use of the options attribute of the parent class ActiveModel::EachValidator.
Add more options: allow_nil, allow_blank, message.
Renamed 'protocols' option to 'schemes' to match the option naming from UrlValidator.
2019-04-11 06:29:07 +00:00

22 lines
511 B
Ruby

# frozen_string_literal: true
module Releases
class Link < ApplicationRecord
self.table_name = 'release_links'
belongs_to :release
validates :url, presence: true, addressable_url: { schemes: %w(http https ftp) }, uniqueness: { scope: :release }
validates :name, presence: true, uniqueness: { scope: :release }
scope :sorted, -> { order(created_at: :desc) }
def internal?
url.start_with?(release.project.web_url)
end
def external?
!internal?
end
end
end