Sha256: b3f944198fe6aea3743300ab19df2548405199f031e7a16708c1e2df42d2eaad

Contents?: true

Size: 1.4 KB

Versions: 15

Compression:

Stored size: 1.4 KB

Contents

module GitReflow
  module GitServer
    autoload :Base,   'git_reflow/git_server/base'
    autoload :GitHub, 'git_reflow/git_server/git_hub'

    extend self

    class ConnectionError < StandardError; end

    def connect(options = nil)
      options ||= { provider: 'GitHub' }
      begin
        provider_name = options[:provider]
        provider = provider_class_for(options.delete(:provider)).new(options)
        provider.authenticate(options.keep_if {|key, value| key == :silent })
        provider
      rescue ConnectionError => e
        puts "Error connecting to #{provider_name}: #{e.message}"
      end
    end

    def connection
      return nil unless current_provider
      current_provider.connection
    end

    def current_provider
      if (provider = GitReflow::Config.get('reflow.git-server')) and provider.length > 0
        begin
          provider_class_for(provider)
        rescue ConnectionError => e
          puts e.message
          nil
        end
      else
        puts "[notice] Reflow hasn't been setup yet.  Run 'git reflow setup' to continue"
        nil
      end
    end

    def can_connect_to?(provider)
      GitReflow::GitServer.const_defined?(provider)
    end

    private

    def provider_class_for(provider)
      raise ConnectionError, "GitServer not setup for \"#{provider}\"" unless self.can_connect_to?(provider)
      GitReflow::GitServer.const_get(provider)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
git_reflow-0.6.7 lib/git_reflow/git_server.rb
git_reflow-0.6.6 lib/git_reflow/git_server.rb
git_reflow-0.6.5 lib/git_reflow/git_server.rb
git_reflow-0.6.4 lib/git_reflow/git_server.rb
git_reflow-0.6.3 lib/git_reflow/git_server.rb
git_reflow-0.6.2 lib/git_reflow/git_server.rb
git_reflow-0.6.1 lib/git_reflow/git_server.rb
git_reflow-0.6.0 lib/git_reflow/git_server.rb
git_reflow-0.5.3 lib/git_reflow/git_server.rb
git_reflow-0.5.2 lib/git_reflow/git_server.rb
git_reflow-0.5.1 lib/git_reflow/git_server.rb
git_reflow-0.5.0 lib/git_reflow/git_server.rb
git_reflow-0.4.2 lib/git_reflow/git_server.rb
git_reflow-0.4.1 lib/git_reflow/git_server.rb
git_reflow-0.4.0 lib/git_reflow/git_server.rb