Class: Git::Object::Tree

Inherits:
AbstractObject show all
Defined in:
lib/git/object.rb

Overview

A Git tree object

Instance Attribute Summary

Attributes inherited from AbstractObject

#mode, #objectish, #size, #type

Instance Method Summary collapse

Methods inherited from AbstractObject

#archive, #blob?, #commit?, #contents, #contents_array, #diff, #grep, #log, #sha, #tag?, #to_s

Constructor Details

#initialize(base, sha, mode = nil) ⇒ Tree

Creates a tree object wrapper

Parameters:

  • base (Git::Repository) —

    the repository used to query object data

  • sha (String) —

    the tree SHA or object expression

  • mode (String, nil) (defaults to: nil) —

    the file mode from tree listings



302
303
304
305
306
307
# File 'lib/git/object.rb', line 302

def initialize(base, sha, mode = nil)
  super(base, sha)
  @mode = mode
  @trees = nil
  @blobs = nil
end

Instance Method Details

#blobs ⇒ Hash<String, Git::Object::Blob> Also known as: files

Returns blobs directly under this tree

Returns:



321
322
323
# File 'lib/git/object.rb', line 321

def blobs
  @blobs ||= check_tree[:blobs]
end

#children ⇒ Hash<String, Git::Object::AbstractObject>

Returns child blobs and subtrees keyed by name

Returns:



313
314
315
# File 'lib/git/object.rb', line 313

def children
  blobs.merge(subtrees)
end

#depth ⇒ Integer

Returns the maximum depth of this tree

Returns:

  • (Integer) —

    maximum tree depth



348
349
350
# File 'lib/git/object.rb', line 348

def depth
  object_repository.tree_depth(@objectish)
end

#full_tree ⇒ Hash

Returns the full tree listing for this tree

Returns:

  • (Hash) —

    parsed recursive tree data



340
341
342
# File 'lib/git/object.rb', line 340

def full_tree
  object_repository.full_tree(@objectish)
end

#tree? ⇒ Boolean

Returns whether this object is a tree

Returns:

  • (Boolean) —

    true



356
357
358
# File 'lib/git/object.rb', line 356

def tree?
  true
end

#trees ⇒ Hash<String, Git::Object::Tree> Also known as: subtrees, subdirectories

Returns subtrees directly under this tree

Returns:



330
331
332
# File 'lib/git/object.rb', line 330

def trees
  @trees ||= check_tree[:trees]
end