summaryrefslogtreecommitdiff
path: root/app/models/tree.rb
blob: 4b6c5b133e9c3574018cc2934353792638d877ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
class Tree
  include Linguist::BlobHelper

  attr_accessor :path, :tree, :ref

  delegate  :contents, :basename, :name, :data, :mime_type,
            :mode, :size, :text?, :colorize, to: :tree

  def initialize(raw_tree, ref = nil, path = nil)
    @ref, @path = ref, path
    @tree = if path.present?
              raw_tree / path
            else
              raw_tree
            end
  end

  def is_blob?
    tree.is_a?(Grit::Blob)
  end

  def invalid?
    tree.nil?
  end

  def empty?
    data.blank?
  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