Class: Gitlab::Git::Tree

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Tree

Returns a new instance of Tree.



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

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

Instance Attribute Details

#commit_idObject

Returns the value of attribute commit_id.



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

def commit_id
  @commit_id
end

#idObject

Returns the value of attribute id.



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

def id
  @id
end

#modeObject

Returns the value of attribute mode.



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

def mode
  @mode
end

#nameObject

Returns the value of attribute name.



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

def name
  @name
end

#pathObject

Returns the value of attribute path.



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

def path
  @path
end

#submodule_urlObject

Returns the value of attribute submodule_url.



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

def submodule_url
  @submodule_url
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Class Method Details

.where(repository, sha, path = '/') ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gitlab_git/tree.rb', line 7

def where(repository, sha, path = '/')
  commit = Commit.find(repository, sha)
  grit_tree = commit.tree / path

  if grit_tree && grit_tree.respond_to?(:contents)
    grit_tree.contents.map do |entry|
      type = entry.class.to_s.split("::").last.downcase.to_sym

      Tree.new(
        id: entry.id,
        name: entry.name,
        type: type,
        mode: entry.mode,
        path: path == '/' ? entry.name : File.join(path, entry.name),
        commit_id: sha,
        submodule_url: (type == :submodule) ? entry.url(sha) : nil
      )
    end
  else
    []
  end
end

Instance Method Details

#dir?Boolean

Returns:

  • (Boolean)


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

def dir?
  type == :tree
end

#file?Boolean

Returns:

  • (Boolean)


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

def file?
  type == :blob
end

#readme?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/gitlab_git/tree.rb', line 49

def readme?
  name =~ /^readme/i
end

#submodule?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/gitlab_git/tree.rb', line 45

def submodule?
  type == :submodule
end