Class: Gitlab::Git::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_git/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository, sha, ref = nil, path = nil) ⇒ Tree

Returns a new instance of Tree.



6
7
8
9
10
11
12
13
14
# File 'lib/gitlab_git/tree.rb', line 6

def initialize(repository, sha, ref = nil, path = nil)
  @repository, @sha, @ref, @path = repository, sha, ref, path

  @path = nil if !@path || @path == ''

  # Load tree from repository
  @commit = @repository.commit(@sha)
  @raw_tree = @repository.tree(@commit, @path)
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/gitlab_git/tree.rb', line 4

def id
  @id
end

#pathObject

Returns the value of attribute path.



4
5
6
# File 'lib/gitlab_git/tree.rb', line 4

def path
  @path
end

#raw_treeObject

Returns the value of attribute raw_tree.



4
5
6
# File 'lib/gitlab_git/tree.rb', line 4

def raw_tree
  @raw_tree
end

#refObject

Returns the value of attribute ref.



4
5
6
# File 'lib/gitlab_git/tree.rb', line 4

def ref
  @ref
end

#repositoryObject

Returns the value of attribute repository.



4
5
6
# File 'lib/gitlab_git/tree.rb', line 4

def repository
  @repository
end

#shaObject

Returns the value of attribute sha.



4
5
6
# File 'lib/gitlab_git/tree.rb', line 4

def sha
  @sha
end

Instance Method Details

#blobsObject



28
29
30
# File 'lib/gitlab_git/tree.rb', line 28

def blobs
  entries.select { |t| t.is_a?(Grit::Blob) }
end

#empty?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/gitlab_git/tree.rb', line 20

def empty?
  trees.empty? && blobs.empty?
end

#exists?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/gitlab_git/tree.rb', line 16

def exists?
  raw_tree
end

#is_blob?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/gitlab_git/tree.rb', line 32

def is_blob?
  raw_tree.is_a?(Grit::Blob)
end

#readmeObject



40
41
42
# File 'lib/gitlab_git/tree.rb', line 40

def readme
  @readme ||= blobs.find { |c| c.name =~ /^readme/i }
end

#treesObject



24
25
26
# File 'lib/gitlab_git/tree.rb', line 24

def trees
  entries.select { |t| t.is_a?(Grit::Tree) }
end

#up_dir?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/gitlab_git/tree.rb', line 36

def up_dir?
  path && path != ''
end