Class: Gitlab::Git::Blob

Inherits:
Object
  • Object
show all
Includes:
Linguist::BlobHelper
Defined in:
lib/gitlab_git/blob.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Blob

Returns a new instance of Blob.



36
37
38
39
40
# File 'lib/gitlab_git/blob.rb', line 36

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

Instance Attribute Details

#commit_id ⇒ Object

Returns the value of attribute commit_id.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def commit_id
  @commit_id
end

#data ⇒ Object

Returns the value of attribute data.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def data
  @data
end

#id ⇒ Object

Returns the value of attribute id.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def id
  @id
end

#mode ⇒ Object

Returns the value of attribute mode.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def mode
  @mode
end

#name ⇒ Object

Returns the value of attribute name.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def name
  @name
end

#path ⇒ Object

Returns the value of attribute path.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def path
  @path
end

#size ⇒ Object

Returns the value of attribute size.



6
7
8
# File 'lib/gitlab_git/blob.rb', line 6

def size
  @size
end

Class Method Details

.find(repository, sha, path) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/gitlab_git/blob.rb', line 9

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

.raw(repository, sha) ⇒ Object



26
27
28
29
30
31
32
33
# File 'lib/gitlab_git/blob.rb', line 26

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

Instance Method Details

#empty? ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/gitlab_git/blob.rb', line 42

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