class Fontist::Repo

Public Class Methods

list() click to toggle source
# File lib/fontist/repo.rb, line 32
def list
  Dir.glob(Fontist.private_formulas_path.join("*"))
    .select { |path| File.directory?(path) }
    .map { |path| File.basename(path) }
end
remove(name) click to toggle source
# File lib/fontist/repo.rb, line 22
def remove(name)
  path = repo_path(name)
  unless Dir.exist?(path)
    raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
  end

  FileUtils.rm_r(path)
  Index.rebuild
end
setup(name, url) click to toggle source
# File lib/fontist/repo.rb, line 6
def setup(name, url)
  ensure_private_formulas_path_exists
  fetch_repo(name, url)
  Index.rebuild
end
update(name) click to toggle source
# File lib/fontist/repo.rb, line 12
def update(name)
  path = repo_path(name)
  unless Dir.exist?(path)
    raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
  end

  Git.open(path).pull
  Index.rebuild
end

Private Class Methods

ensure_private_formulas_path_exists() click to toggle source
# File lib/fontist/repo.rb, line 40
def ensure_private_formulas_path_exists
  Fontist.private_formulas_path.tap do |path|
    FileUtils.mkdir_p(path) unless Dir.exist?(path)
  end
end
fetch_repo(name, url) click to toggle source
# File lib/fontist/repo.rb, line 46
def fetch_repo(name, url)
  path = repo_path(name)
  if Dir.exist?(path)
    Git.open(path).pull
  else
    Git.clone(url, path, depth: 1)
  end
end
repo_path(name) click to toggle source
# File lib/fontist/repo.rb, line 55
def repo_path(name)
  Fontist.private_formulas_path.join(name)
end