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_exists?(file_name) ⇒ Boolean
Looks for a file and returns true when the file can be found.
-
#file_with_content_exists?(file_name) ⇒ Boolean
Looks for a file and yields the file content to the block (if the file can be found).
-
#find_blob(blob_name, current_tree = root_tree) {|Rugged::Blob| ... } ⇒ Rugged::Blob
Recursively searches for the blob identified by ‘blob_name` in 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.
51 52 53 |
# File 'lib/technologist/git_repository.rb', line 51 def directory_exists?(directory_name) !!find_blob(directory_name) end |
#file_exists?(file_name) ⇒ Boolean
Looks for a file and returns true when the file can be found.
61 62 63 |
# File 'lib/technologist/git_repository.rb', line 61 def file_exists?(file_name) !!find_blob(file_name) end |
#file_with_content_exists?(file_name) ⇒ Boolean
Looks for a file and yields the file content to the block (if the file can be found). The block’s return value is used to determine if we’re done searching. If the return value is ‘false`, we keep searching for the file.
74 75 76 77 78 |
# File 'lib/technologist/git_repository.rb', line 74 def file_with_content_exists?(file_name) !!find_blob(file_name) do |file| yield file.content end end |
#find_blob(blob_name, current_tree = root_tree) {|Rugged::Blob| ... } ⇒ 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.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/technologist/git_repository.rb', line 28 def find_blob(blob_name, current_tree = root_tree, &block) blob = current_tree[blob_name] if blob blob = repository.lookup(blob[:oid]) if !block_given? || yield(blob) return blob end end # recurse current_tree.each_tree do |sub_tree| blob = find_blob(blob_name, repository.lookup(sub_tree[:oid]), &block) break blob if blob end end |
#root_tree ⇒ Object
11 12 13 |
# File 'lib/technologist/git_repository.rb', line 11 def root_tree repository.head.target.tree end |