summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/external/file/local.rb
blob: 1aa7f687507705c9185ee463e4c04266bf9c8e1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# frozen_string_literal: true

module Gitlab
  module Ci
    module External
      module File
        class Local < Base
          attr_reader :location, :project, :sha

          def initialize(location, opts = {})
            super

            @project = opts.fetch(:project)
            @sha = opts.fetch(:sha)
          end

          def content
            @content ||= fetch_local_content
          end

          def error_message
            "Local file '#{location}' is not valid."
          end

          private

          def fetch_local_content
            project.repository.blob_data_at(sha, location)
          end
        end
      end
    end
  end
end