2019-02-15 15:39:39 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Releases
|
2019-07-07 11:18:12 +05:30
|
|
|
class Link < ApplicationRecord
|
2019-02-15 15:39:39 +05:30
|
|
|
self.table_name = 'release_links'
|
|
|
|
|
|
|
|
belongs_to :release
|
|
|
|
|
2020-04-08 14:13:33 +05:30
|
|
|
FILEPATH_REGEX = /\A\/([\-\.\w]+\/?)*[\da-zA-Z]+\z/.freeze
|
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
validates :url, presence: true, addressable_url: { schemes: %w(http https ftp) }, uniqueness: { scope: :release }
|
2019-02-15 15:39:39 +05:30
|
|
|
validates :name, presence: true, uniqueness: { scope: :release }
|
2020-04-08 14:13:33 +05:30
|
|
|
validates :filepath, uniqueness: { scope: :release }, format: { with: FILEPATH_REGEX }, allow_blank: true, length: { maximum: 128 }
|
2019-02-15 15:39:39 +05:30
|
|
|
|
|
|
|
scope :sorted, -> { order(created_at: :desc) }
|
|
|
|
|
|
|
|
def internal?
|
|
|
|
url.start_with?(release.project.web_url)
|
|
|
|
end
|
|
|
|
|
|
|
|
def external?
|
|
|
|
!internal?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|