Class: Gitlab::Git::Tree
- Inherits:
-
Object
- Object
- Gitlab::Git::Tree
- Defined in:
- lib/gitlab_git/tree.rb
Instance Attribute Summary collapse
-
#commit_id ⇒ Object
Returns the value of attribute commit_id.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#submodule_url ⇒ Object
Returns the value of attribute submodule_url.
-
#type ⇒ Object
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
- #dir? ⇒ Boolean
- #file? ⇒ Boolean
-
#initialize(options) ⇒ Tree
constructor
A new instance of Tree.
- #readme? ⇒ Boolean
- #submodule? ⇒ Boolean
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() %w(id name path type mode commit_id submodule_url).each do |key| self.send("#{key}=", [key.to_sym]) end end |
Instance Attribute Details
#commit_id ⇒ Object
Returns the value of attribute commit_id.
4 5 6 |
# File 'lib/gitlab_git/tree.rb', line 4 def commit_id @commit_id end |
#id ⇒ Object
Returns the value of attribute id.
4 5 6 |
# File 'lib/gitlab_git/tree.rb', line 4 def id @id end |
#mode ⇒ Object
Returns the value of attribute mode.
4 5 6 |
# File 'lib/gitlab_git/tree.rb', line 4 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/gitlab_git/tree.rb', line 4 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
4 5 6 |
# File 'lib/gitlab_git/tree.rb', line 4 def path @path end |
#submodule_url ⇒ Object
Returns the value of attribute submodule_url.
4 5 6 |
# File 'lib/gitlab_git/tree.rb', line 4 def submodule_url @submodule_url end |
#type ⇒ Object
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
37 38 39 |
# File 'lib/gitlab_git/tree.rb', line 37 def dir? type == :tree end |
#file? ⇒ Boolean
41 42 43 |
# File 'lib/gitlab_git/tree.rb', line 41 def file? type == :blob end |
#readme? ⇒ Boolean
49 50 51 |
# File 'lib/gitlab_git/tree.rb', line 49 def readme? name =~ /^readme/i end |
#submodule? ⇒ Boolean
45 46 47 |
# File 'lib/gitlab_git/tree.rb', line 45 def submodule? type == :submodule end |