Class: GitFileReader
- Inherits:
-
Object
- Object
- GitFileReader
- Defined in:
- lib/git_file_reader.rb
Overview
TODO: Not used yet. Either implement git-related functionality or delete this file and its tests
Instance Method Summary collapse
- #blob_at(ref, path) ⇒ Object
- #commit_for_ref(ref) ⇒ Object
-
#contents(filename) ⇒ Object
Content of desired file.
-
#initialize(repo_dir = '.') ⇒ GitFileReader
constructor
A new instance of GitFileReader.
Constructor Details
#initialize(repo_dir = '.') ⇒ GitFileReader
Returns a new instance of GitFileReader.
5 6 7 |
# File 'lib/git_file_reader.rb', line 5 def initialize(repo_dir = '.') @repo = Rugged::Repository.new repo_dir end |
Instance Method Details
#blob_at(ref, path) ⇒ Object
9 10 11 12 |
# File 'lib/git_file_reader.rb', line 9 def blob_at(ref, path) commit = @repo.rev_parse ref # Rugged::Commit @repo.blob_at(commit.oid, path) # Rugged::Blob end |
#commit_for_ref(ref) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/git_file_reader.rb', line 14 def commit_for_ref(ref) reference = @repo.ref ref # Rugged::Reference abort "Error: #{ref} is an invalid ref" if reference.nil? reference_direct = reference.type == :symbolic ? reference.target : reference @commit = reference_direct.target # Rugged::Commit self end |
#contents(filename) ⇒ Object
Returns content of desired file.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/git_file_reader.rb', line 24 def contents(filename) abort('Error: @commit is undefined; invoke commit_for_ref before invoking contents') if @commit.nil? tree = @commit.tree # Rugged::Tree entry = tree.get_entry filename # hash abort("Error: #{filename} is not present in commit #{commit.oid}") if entry.nil? sha = entry[:oid] # String object = @repo.read sha # Rugged::ObdObject; this is a blob object.data # String end |