class Minimart::Download::GitCache
GitCache
manages cloning repositories, and storing them for later access.
Attributes
Public Class Methods
Get the GitCache
singleton instance @return [Minimart::Download::GitCache]
# File lib/minimart/download/git_cache.rb, line 9 def instance @instance ||= GitCache.new end
# File lib/minimart/download/git_cache.rb, line 14 def initialize self.cache = {} end
Public Instance Methods
This method will empty the GitCache
.
# File lib/minimart/download/git_cache.rb, line 35 def clear cache.values.each do |git| FileUtils.remove_entry(git.repo.path) end self.cache = {} end
Get a repository from the GitCache
. This repository will be cloned, if it hasn't been already. @param [String] repo_location Any location that can be cloned by Git (Path, URL). @return [Git::Base]
# File lib/minimart/download/git_cache.rb, line 22 def get_repository(repo_location) cache[repo_location] ||= clone_bare_repo(repo_location) end
See if the GitCache
has any reference to a repository location. @param [String] repo_location Any location that can be cloned by Git (Path, URL). @return [Boolean]
# File lib/minimart/download/git_cache.rb, line 45 def has_location?(repo_location) cache.has_key? repo_location end
Get the local path to the repository passed in. This repository will be cloned, if it hasn't been already. @param [String] repo_location Any location that can be cloned by Git (Path, URL). @return [String] The path to the repository
# File lib/minimart/download/git_cache.rb, line 30 def local_path_for(repo_location) get_repository(repo_location).repo.path end
Private Instance Methods
# File lib/minimart/download/git_cache.rb, line 53 def clone_bare_repo(repo_location) Configuration.output.puts "-- Cloning Git Repository From '#{repo_location}'" Git.clone(repo_location, Dir.mktmpdir, bare: true) end