summaryrefslogtreecommitdiff
path: root/app/models/lfs_download_object.rb
blob: 6383f95d5463d6d75d265d9df41f8f6a1aca91af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# frozen_string_literal: true

class LfsDownloadObject
  include ActiveModel::Validations

  attr_accessor :oid, :size, :link
  delegate :sanitized_url, :credentials, to: :sanitized_uri

  validates :oid, format: { with: /\A\h{64}\z/ }
  validates :size, numericality: { greater_than_or_equal_to: 0 }
  validates :link, public_url: { protocols: %w(http https) }

  def initialize(oid:, size:, link:)
    @oid = oid
    @size = size
    @link = link
  end

  def sanitized_uri
    @sanitized_uri ||= Gitlab::UrlSanitizer.new(link)
  end
end