link.rb 502 Bytes
Newer Older
1 2 3 4 5 6 7 8
# frozen_string_literal: true

module Releases
  class Link < ActiveRecord::Base
    self.table_name = 'release_links'

    belongs_to :release

9
    validates :url, presence: true, url: { protocols: %w(http https ftp) }, uniqueness: { scope: :release }
10 11 12 13 14 15 16 17 18 19 20 21 22
    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