Class: Technologist::GitRepository
- Inherits:
-
Object
- Object
- Technologist::GitRepository
- Defined in:
- lib/technologist/git_repository.rb
Instance Attribute Summary collapse
-
#repository ⇒ Object
readonly
Returns the value of attribute repository.
Instance Method Summary collapse
-
#directory_exists?(directory_name) ⇒ Boolean
Looks for a directory and returns true when the directory can be found.
-
#file_content(file_name) ⇒ String
Returns the file content.
-
#file_exists?(file_name) ⇒ Boolean
Looks for a file and returns true when the file can be found.
-
#find_blob(blob_name, current_tree = root_tree) ⇒ Rugged::Blob
Recursively searches for the blob identified by
blob_namein all subdirectories in the repository. -
#initialize(repository_path) ⇒ GitRepository
constructor
A new instance of GitRepository.
- #root_tree ⇒ Object
Constructor Details
#initialize(repository_path) ⇒ GitRepository
Returns a new instance of GitRepository.
7 8 9 |
# File 'lib/technologist/git_repository.rb', line 7 def initialize(repository_path) @repository = Rugged::Repository.new(repository_path) end |
Instance Attribute Details
#repository ⇒ Object (readonly)
Returns the value of attribute repository.
5 6 7 |
# File 'lib/technologist/git_repository.rb', line 5 def repository @repository end |
Instance Method Details
#directory_exists?(directory_name) ⇒ Boolean
Looks for a directory and returns true when the directory can be found.
54 55 56 |
# File 'lib/technologist/git_repository.rb', line 54 def directory_exists?(directory_name) !!find_blob(directory_name) end |
#file_content(file_name) ⇒ String
Returns the file content.
20 21 22 23 24 |
# File 'lib/technologist/git_repository.rb', line 20 def file_content(file_name) file = find_blob(file_name) file.content if file end |
#file_exists?(file_name) ⇒ Boolean
Looks for a file and returns true when the file can be found.
64 65 66 |
# File 'lib/technologist/git_repository.rb', line 64 def file_exists?(file_name) !!find_blob(file_name) end |
#find_blob(blob_name, current_tree = root_tree) ⇒ Rugged::Blob
Recursively searches for the blob identified by blob_name in all subdirectories in the repository. A blob is usually either a file or a directory.
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/technologist/git_repository.rb', line 35 def find_blob(blob_name, current_tree = root_tree) blob = current_tree[blob_name] if blob repository.lookup(blob[:oid]) else current_tree.each_tree do |sub_tree| blob = find_blob(blob_name, repository.lookup(sub_tree[:oid])) break blob if blob end end end |
#root_tree ⇒ Object
11 12 13 |
# File 'lib/technologist/git_repository.rb', line 11 def root_tree repository.head.target.tree end |