gitlab-org--gitlab-foss/app/models/tree.rb

36 lines
932 B
Ruby
Raw Normal View History

2011-11-20 15:32:12 -05:00
class Tree
attr_accessor :entries, :readme, :contribution_guide
2011-11-20 15:32:12 -05:00
2013-10-01 10:00:28 -04:00
def initialize(repository, sha, path = '/')
path = '/' if path.blank?
git_repo = repository.raw_repository
@entries = Gitlab::Git::Tree.where(git_repo, sha, path)
if readme_tree = @entries.find(&:readme?)
2013-10-13 09:03:16 -04:00
readme_path = path == '/' ? readme_tree.name : File.join(path, readme_tree.name)
@readme = Gitlab::Git::Blob.find(git_repo, sha, readme_path)
2013-10-01 10:00:28 -04:00
end
if contribution_tree = @entries.find(&:contributing?)
contribution_path = path == '/' ? contribution_tree.name : File.join(path, contribution_tree.name)
@contribution_guide = Gitlab::Git::Blob.find(git_repo, sha, contribution_path)
end
2011-11-20 15:32:12 -05:00
end
2011-11-22 07:50:47 -05:00
2013-10-01 10:00:28 -04:00
def trees
@entries.select(&:dir?)
2011-11-22 07:50:47 -05:00
end
2013-10-01 10:00:28 -04:00
def blobs
@entries.select(&:file?)
end
2013-10-01 10:00:28 -04:00
def submodules
@entries.select(&:submodule?)
end
def sorted_entries
trees + blobs + submodules
end
2011-11-20 15:32:12 -05:00
end