Sha256: 7a7bb658066acdb194494608ae436e8cf773b3c95f87614d46f91778df97d7dc

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

module Gitlab
  module Git
    class Blob
      include Linguist::BlobHelper

      attr_accessor :name, :path, :size, :data, :mode, :id, :commit_id

      class << self
        def find(repository, sha, path)
          commit = Commit.find(repository, sha)
          grit_blob = commit.tree / path

          if grit_blob.kind_of?(Grit::Blob)
            Blob.new(
              id: grit_blob.id,
              name: grit_blob.name,
              size: grit_blob.size,
              data: grit_blob.data,
              mode: grit_blob.mode,
              path: path,
              commit_id: sha,
            )
          end
        end

        def raw(repository, sha)
          grit_blob = repository.grit.blob(sha)
          Blob.new(
            id: grit_blob.id,
            size: grit_blob.size,
            data: grit_blob.data,
          )
        end
      end

      def initialize(options)
        %w(id name path size data mode commit_id).each do |key|
          self.send("#{key}=", options[key.to_sym])
        end
      end

      def empty?
        !data || data == ''
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gitlab_git-5.0.0 lib/gitlab_git/blob.rb
gitlab_git-4.1.0 lib/gitlab_git/blob.rb
gitlab_git-4.0.0 lib/gitlab_git/blob.rb