gitlab-org--gitlab-foss/lib/gitlab/git/tree.rb
2013-04-02 21:30:36 +03:00

38 lines
740 B
Ruby

module Gitlab
module Git
class Tree
include Linguist::BlobHelper
attr_accessor :repository, :sha, :path, :ref, :raw_tree
def initialize(repository, sha, ref = nil, path = nil)
@repository, @sha, @ref = repository, sha, ref
# Load tree from repository
@commit = @repository.commit(sha)
@raw_tree = @repository.tree(@commit, path)
end
def empty?
data.blank?
end
def data
raw_tree.data
end
def is_blob?
tree.is_a?(Grit::Blob)
end
def up_dir?
path.present?
end
def readme
@readme ||= contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }
end
end
end
end