Class: Git::GitAltURI Private

Inherits:
Addressable::URI
  • Object
show all
Defined in:
lib/git/url.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The URI for git's alternative scp-like syntax

This class is necessary to ensure that #to_s returns the same string that was passed to the initializer.

Instance Method Summary collapse

Constructor Details

#initialize(user:, host:, path:) ⇒ GitAltURI

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Create a new GitAltURI object

Examples:

uri = Git::GitAltURI.new(user: 'james', host: 'github.com', path: 'james/ruby-git')
uri.to_s #=> 'james@github.com/james/ruby-git'

Parameters:

  • user (String, nil)

    the user from the URL or nil

  • host (String)

    the host from the URL

  • path (String)

    the path from the URL



103
104
105
# File 'lib/git/url.rb', line 103

def initialize(user:, host:, path:)
  super(scheme: 'git-alt', user: user, host: host, path: path)
end

Instance Method Details

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Convert the URI to a String

Addressible::URI forces path to be absolute by prepending a '/' to the path. This method removes the '/' when converting back to a string since that is what is expected by git. The following is a valid git URL:

james@github.com:ruby-git/ruby-git.git

and the following (with the initial '/'' in the path) is NOT a valid git URL:

james@github.com:/ruby-git/ruby-git.git

Examples:

uri = Git::GitAltURI.new(user: 'james', host: 'github.com', path: 'james/ruby-git')
uri.path #=> '/james/ruby-git'
uri.to_s #=> 'james@github.com:james/ruby-git'

Returns:

  • (String)

    the URI as a String



126
127
128
129
130
131
132
# File 'lib/git/url.rb', line 126

def to_s
  if user
    "#{user}@#{host}:#{path[1..]}"
  else
    "#{host}:#{path[1..]}"
  end
end