Sha256: 6fc137005a394c359a5c031fb385758b08501777c26d63d0ebff12cb32cf30c6

Contents?: true

Size: 1.18 KB

Versions: 2

Compression:

Stored size: 1.18 KB

Contents

require 'uri'

require 'uri/ssh_git/generic'
require 'uri/ssh_git/version'

module URI
  # Parse and build git repository url via ssh protocol.
  module SshGit
    # @example
    #   url = URI::SshGit.parse('git@github.com:packsaddle/ruby-uri-ssh_git.git')
    #   #=> #<URI::SshGit::Generic git@github.com:packsaddle/ruby-uri-ssh_git.git>
    #
    #   url.scheme #=> nil
    #   url.userinfo #=> 'git'
    #   url.user #=> 'git'
    #   url.password #=> nil
    #   url.host #=> 'github.com'
    #   url.port #=> nil
    #   url.registry #=> nil
    #   url.path #=> 'packsaddle/ruby-uri-ssh_git.git'
    #   url.opaque #=> nil
    #   url.query #=> nil
    #   url.fragment #=> nil
    #
    # @see http://docs.ruby-lang.org/en/2.2.0/URI/Generic.html
    #
    # @param url [String] git repository url via ssh protocol
    #
    # @return [Generic] parsed object
    def self.parse(uri_string)
      host_part, path_part = uri_string.split(':', 2)
      # There may be no user, so reverse the split to make sure host always
      # is !nil if host_part was !nil.
      host, userinfo = host_part.split('@', 2).reverse
      Generic.build(userinfo: userinfo, host: host, path: path_part)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
uri-ssh_git-2.0.0 lib/uri/ssh_git.rb
uri-ssh_git-2.0.0.pre.1 lib/uri/ssh_git.rb