Sha256: cb72a0602a37697845d4d93fc3533a32842a435ad0b9bcb86084fbd7450f0484

Contents?: true

Size: 1.3 KB

Versions: 9

Compression:

Stored size: 1.3 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

      def list
        Dir.glob(Fontist.private_formulas_path.join("*"))
          .select { |path| File.directory?(path) }
          .map { |path| File.basename(path) }
      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

9 entries across 9 versions & 1 rubygems

Version Path
fontist-1.11.5 lib/fontist/repo.rb
fontist-1.11.3 lib/fontist/repo.rb
fontist-1.11.2 lib/fontist/repo.rb
fontist-1.9.3 lib/fontist/repo.rb
fontist-1.9.2 lib/fontist/repo.rb
fontist-1.11.1 lib/fontist/repo.rb
fontist-1.10.1 lib/fontist/repo.rb
fontist-1.10.0 lib/fontist/repo.rb
fontist-1.9.1 lib/fontist/repo.rb