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.



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

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_idObject

Returns the value of attribute commit_id.



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

def commit_id
  @commit_id
end

#dataObject

Returns the value of attribute data.



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

def data
  @data
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#modeObject

Returns the value of attribute mode.



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

def mode
  @mode
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#sizeObject

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

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gitlab_git/blob.rb', line 33

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