Sha256: 87f3f4677459c457634ecfee4a9a92f3dfee6e93c83cd59304564f224ebcbfa9

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require "git"

module Fontist
  class Repo
    class << self
      def setup(name, url)
        ensure_private_formulas_path_exists
        fetch_repo(name, url)
        Index.rebuild
      end

      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

      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

      private

      def ensure_private_formulas_path_exists
        Fontist.private_formulas_path.tap do |path|
          FileUtils.mkdir_p(path) unless Dir.exist?(path)
        end
      end

      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

      def repo_path(name)
        Fontist.private_formulas_path.join(name)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fontist-1.9.0 lib/fontist/repo.rb