Class: Amp::Core::Repositories::Git::Index::AbstractIndex
- Inherits:
-
Object
- Object
- Amp::Core::Repositories::Git::Index::AbstractIndex
- Defined in:
- lib/amp-git/repo_format/index.rb
Overview
Generic Index class, handles common initialization and generic methods that aren’t different between different versions of the index
Direct Known Subclasses
Instance Method Summary collapse
-
#[](name) ⇒ IndexEntry, NilClass
Returns an IndexEntry for the file with the given name.
-
#initialize(fp) ⇒ AbstractIndex
constructor
A new instance of AbstractIndex.
- #inspect ⇒ Object
- #read_entries(fp) ⇒ Object
-
#size ⇒ Integer
The number of entries in the Index.
Constructor Details
#initialize(fp) ⇒ AbstractIndex
Returns a new instance of AbstractIndex.
113 114 115 116 |
# File 'lib/amp-git/repo_format/index.rb', line 113 def initialize(fp) @entry_map = {} @entry_count = fp.read(4).unpack("N").first end |
Instance Method Details
#[](name) ⇒ IndexEntry, NilClass
Returns an IndexEntry for the file with the given name. Returns nil on failure, and this should not be used by end-users
130 131 132 |
# File 'lib/amp-git/repo_format/index.rb', line 130 def [](name) @entry_map[name] end |
#inspect ⇒ Object
143 144 145 |
# File 'lib/amp-git/repo_format/index.rb', line 143 def inspect "<Git Index, entries: #{@entry_count}>" end |
#read_entries(fp) ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/amp-git/repo_format/index.rb', line 134 def read_entries(fp) @entries = [] @entry_count.times do new_entry = IndexEntry.new(fp) @entries << new_entry @entry_map[new_entry.name] = new_entry end end |
#size ⇒ Integer
Returns the number of entries in the Index.
120 121 122 |
# File 'lib/amp-git/repo_format/index.rb', line 120 def size @entry_count end |