class Minimart::Download::GitCache

GitCache manages cloning repositories, and storing them for later access.

Attributes

cache[RW]

Public Class Methods

instance() click to toggle source

Get the GitCache singleton instance @return [Minimart::Download::GitCache]

# File lib/minimart/download/git_cache.rb, line 9
def instance
  @instance ||= GitCache.new
end
new() click to toggle source
# File lib/minimart/download/git_cache.rb, line 14
def initialize
  self.cache = {}
end

Public Instance Methods

clear() click to toggle source

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_repository(repo_location) click to toggle source

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
has_location?(repo_location) click to toggle source

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
local_path_for(repo_location) click to toggle source

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

clone_bare_repo(repo_location) click to toggle source
# 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