2011-11-20 15:32:12 -05:00
|
|
|
class Tree
|
2012-09-17 12:38:59 -04:00
|
|
|
include Linguist::BlobHelper
|
2011-11-20 15:32:12 -05:00
|
|
|
attr_accessor :path, :tree, :project, :ref
|
|
|
|
|
2012-09-27 02:20:36 -04:00
|
|
|
delegate :contents, :basename, :name, :data, :mime_type,
|
|
|
|
:mode, :size, :text?, :colorize, to: :tree
|
2011-11-20 15:32:12 -05:00
|
|
|
|
|
|
|
def initialize(raw_tree, project, ref = nil, path = nil)
|
2012-09-17 12:38:59 -04:00
|
|
|
@project, @ref, @path = project, ref, path
|
|
|
|
@tree = if path.present?
|
2012-09-11 07:18:14 -04:00
|
|
|
raw_tree / path.dup.force_encoding('ascii-8bit')
|
2011-11-20 15:32:12 -05:00
|
|
|
else
|
|
|
|
raw_tree
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_blob?
|
|
|
|
tree.is_a?(Grit::Blob)
|
|
|
|
end
|
2011-11-22 07:50:47 -05:00
|
|
|
|
2012-09-17 12:38:59 -04:00
|
|
|
def invalid?
|
|
|
|
tree.nil?
|
|
|
|
end
|
|
|
|
|
2011-11-22 07:50:47 -05:00
|
|
|
def empty?
|
|
|
|
data.blank?
|
|
|
|
end
|
2011-11-20 15:32:12 -05:00
|
|
|
end
|