In Files

Parent

Files

Grit::Tree

Attributes

id[R]
mode[R]
name[R]

Public Class Methods

construct(repo, treeish, paths = []) click to toggle source

Construct the contents of the tree

+repo+ is the Repo
+treeish+ is the reference
+paths+ is an optional Array of directory paths to restrict the tree

Returns Grit::Tree (baked)

# File lib/grit/tree.rb, line 17
def self.construct(repo, treeish, paths = [])
  output = repo.git.ls_tree({}, treeish, *paths)
  self.allocate.construct_initialize(repo, treeish, output)
end
create(repo, atts) click to toggle source

Create an unbaked Tree containing just the specified attributes

+repo+ is the Repo
+atts+ is a Hash of instance variable data

Returns Grit::Tree (unbaked)

# File lib/grit/tree.rb, line 44
def self.create(repo, atts)
  self.allocate.create_initialize(repo, atts)
end

Public Instance Methods

/(file) click to toggle source

Find the named object in this tree’s contents

Examples

Repo.new('/path/to/grit').tree/'lib'
# => #<Grit::Tree "6cc23ee138be09ff8c28b07162720018b244e95e">
Repo.new('/path/to/grit').tree/'README.txt'
# => #<Grit::Blob "8b1e02c0fb554eed2ce2ef737a68bb369d7527df">

Returns Grit::Blob or Grit::Tree or nil if not found

# File lib/grit/tree.rb, line 92
def /(file)
  if file =~ /\//
    file.split("/").inject(self) { |acc, x| acc/x } rescue nil
  else
    self.contents.find { |c| c.name == file }
  end
end
<=>(other) click to toggle source

Compares trees by name

# File lib/grit/tree.rb, line 120
def <=>(other)
  name <=> other.name
end
basename() click to toggle source
# File lib/grit/tree.rb, line 100
def basename
  File.basename(name)
end
blobs() click to toggle source

Find only Blob objects from contents

# File lib/grit/tree.rb, line 115
def blobs
  contents.select {|v| v.kind_of? Blob}
end
construct_initialize(repo, id, text) click to toggle source
# File lib/grit/tree.rb, line 22
def construct_initialize(repo, id, text)
  @repo = repo
  @id = id
  @contents = []

  text.split("\n").each do |line|
    @contents << content_from_string(repo, line)
  end
  @contents.compact!

  self
end
content_from_string(repo, text) click to toggle source

Parse a content item and create the appropriate object

+repo+ is the Repo
+text+ is the single line containing the items data in `git ls-tree` format

Returns Grit::Blob or Grit::Tree

# File lib/grit/tree.rb, line 67
def content_from_string(repo, text)
  mode, type, id, name = text.split(" ", 4)
  case type
    when "tree"
      Tree.create(repo, :id => id, :mode => mode, :name => name)
    when "blob"
      Blob.create(repo, :id => id, :mode => mode, :name => name)
    when "link"
      Blob.create(repo, :id => id, :mode => mode, :name => name)
    when "commit"
      Submodule.create(repo, :id => id, :mode => mode, :name => name)
    else
      raise Grit::InvalidObjectType, type
  end
end
create_initialize(repo, atts) click to toggle source

Initializer for Tree.create

+repo+ is the Repo
+atts+ is a Hash of instance variable data

Returns Grit::Tree (unbaked)

# File lib/grit/tree.rb, line 53
def create_initialize(repo, atts)
  @repo = repo

  atts.each do |k, v|
    instance_variable_set("@#{k}", v)
  end
  self
end
inspect() click to toggle source

Pretty object inspection

# File lib/grit/tree.rb, line 105
def inspect
  %{#<Grit::Tree "#{@id}">}
end
lazy_source() click to toggle source
# File lib/grit/tree.rb, line 35
def lazy_source
  Tree.construct(@repo, @id, [])
end
trees() click to toggle source

Find only Tree objects from contents

# File lib/grit/tree.rb, line 110
def trees
  contents.select {|v| v.kind_of? Tree}
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.