Class: Amp::Core::Repositories::Git::Index::AbstractIndex

Inherits:
Object
  • Object
show all
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

IndexVersion1, IndexVersion2

Instance Method Summary collapse

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

Parameters:

  • name (String)

    the name of the object/file to look up

Returns:

  • (IndexEntry, NilClass)

    the entry with the given name, or nil



130
131
132
# File 'lib/amp-git/repo_format/index.rb', line 130

def [](name)
  @entry_map[name]
end

#inspectObject



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

#sizeInteger

Returns the number of entries in the Index.

Returns:

  • (Integer)

    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