Sha256: 77797058d88716e5a9694b09db4ea6adc1cfe1503b965db3beeadcf70960d24f

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 KB

Contents

module Vimmer
  module Installers
    class Github
      attr_reader :path, :plugin_name

      def initialize(args={})
        if args[:path]
          initialize_with_path(args[:path])
        elsif args[:name]
          initialize_with_name(args[:name])
        end
      end


      def install
        if path_exists?
          git_clone(path, File.join(Vimmer.bundle_path, plugin_name))
          Vimmer.add_plugin(plugin_name, path)
          puts "#{plugin_name} has been installed"
        else
          raise Vimmer::PluginNotFoundError
        end
      end


      def uninstall
        FileUtils.rm_rf(File.join(Vimmer.bundle_path, plugin_name))
        Vimmer.remove_plugin(plugin_name)
      end


      def path_exists?
        `curl --head -w %{http_code} -o /dev/null #{remove_extension(path)} 2> /dev/null`.chomp == "200"
      end


      private

      def git_clone(path, install_to)
        output = `git clone #{path} #{install_to}`
      end


      def initialize_with_path(path)
        raise Vimmer::InvalidPathError.new(path) unless path =~ %r{^https://github.com/[a-zA-Z0-9\-_\+%]+/([a-zA-Z0-9\-_\+]+).git$}
        @plugin_name = $1
        @path = path
      end


      def initialize_with_name(name)
        @path = Vimmer.plugins[name]
        @plugin_name = name
      end

      def remove_extension(path)
        path.gsub(/\.git$/, '')
      end

    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vimmer-0.1.0 lib/vimmer/installers/github.rb