2011-11-20 21:32:12 +01:00
|
|
|
class Tree
|
2012-09-17 18:38:59 +02:00
|
|
|
include Linguist::BlobHelper
|
2013-01-03 20:09:18 +01:00
|
|
|
|
|
|
|
attr_accessor :path, :tree, :ref
|
2011-11-20 21:32:12 +01:00
|
|
|
|
2012-09-27 08:20:36 +02:00
|
|
|
delegate :contents, :basename, :name, :data, :mime_type,
|
|
|
|
:mode, :size, :text?, :colorize, to: :tree
|
2011-11-20 21:32:12 +01:00
|
|
|
|
2013-01-03 20:09:18 +01:00
|
|
|
def initialize(raw_tree, ref = nil, path = nil)
|
|
|
|
@ref, @path = ref, path
|
2012-09-17 18:38:59 +02:00
|
|
|
@tree = if path.present?
|
2012-11-08 18:41:07 +01:00
|
|
|
raw_tree / path
|
2011-11-20 21:32:12 +01:00
|
|
|
else
|
|
|
|
raw_tree
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_blob?
|
|
|
|
tree.is_a?(Grit::Blob)
|
|
|
|
end
|
2011-11-22 13:50:47 +01:00
|
|
|
|
2012-09-17 18:38:59 +02:00
|
|
|
def invalid?
|
|
|
|
tree.nil?
|
|
|
|
end
|
|
|
|
|
2011-11-22 13:50:47 +01:00
|
|
|
def empty?
|
|
|
|
data.blank?
|
|
|
|
end
|
2013-03-31 22:48:12 +02:00
|
|
|
|
|
|
|
def up_dir?
|
|
|
|
path.present?
|
|
|
|
end
|
|
|
|
|
|
|
|
def readme
|
|
|
|
@readme ||= contents.find { |c| c.is_a?(Grit::Blob) and c.name =~ /^readme/i }
|
|
|
|
end
|
2011-11-20 21:32:12 +01:00
|
|
|
end
|