Class: Amp::Core::Repositories::Git::TreeObject

Inherits:
RawObject
  • Object
show all
Defined in:
lib/amp-git/repo_format/tree_object.rb

Overview

TreeObject

This is a tree object representing a versioned directory. It has a list of

Defined Under Namespace

Classes: TreeEntry

Constant Summary

Constants inherited from RawObject

RawObject::AUTHOR_MATCH

Instance Attribute Summary

Attributes inherited from RawObject

#content, #hash_id, #type

Instance Method Summary collapse

Methods inherited from RawObject

construct, for_hash

Constructor Details

#initialize(hsh, opener, content = nil) ⇒ TreeObject

Initializes the RawObject. Needs a hash to identify it and an opener. The opener should point to the .git directory.

Parameters:

  • hsh (String)

    the hash to use to find the object

  • opener (Support::RootedOpener)

    the opener to use to open the object file

  • content (String) (defaults to: nil)

    if the content is known already, use the provided content instead



42
43
44
45
46
47
48
49
50
51
# File 'lib/amp-git/repo_format/tree_object.rb', line 42

def initialize(hsh, opener, content = nil)
  if content
    @hash_id, @opener = hsh, opener
    @type = 'tree'
    @content = content
  else
    super(hsh, opener)
  end
  parse!
end

Instance Method Details

#entry_namesArray<String>

Returns a list of the names of the files/directories (blobs/trees) in the tree

Returns:

  • (Array<String>)

    a (possibly unsorted) list of file and and directory names in this tree



59
60
61
# File 'lib/amp-git/repo_format/tree_object.rb', line 59

def entry_names
  @pairs.keys
end

#sizeFixnum

Returns the number of entries in the directory.

Returns:

  • (Fixnum)

    the number of entries in this directory



67
68
69
# File 'lib/amp-git/repo_format/tree_object.rb', line 67

def size
  @pairs.size
end

#tree_lookup(name) ⇒ TreeEntry

Returns a TreeObject for the given filename in this level of the tree.

Parameters:

  • name (String)

    the name of the file to look up

Returns:

  • (TreeEntry)

    the treeobject representing the file



77
78
79
# File 'lib/amp-git/repo_format/tree_object.rb', line 77

def tree_lookup(name)
  @pairs[name]
end