class Git::GitAltURI
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.
@api public
Public Class Methods
new(user:, host:, path:)
click to toggle source
Create a new GitAltURI
object
@example
uri = Git::GitAltURI.new(user: 'james', host: 'github.com', path: 'james/ruby-git') uri.to_s #=> 'james@github.com/james/ruby-git'
@param user [String, nil] the user from the URL
or nil @param host [String] the host from the URL
@param path [String] the path from the URL
Calls superclass method
# File lib/git/url.rb, line 96 def initialize(user:, host:, path:) super(scheme: 'git-alt', user: user, host: host, path: path) end
Public Instance Methods
to_s()
click to toggle source
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`
@example
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'
@return [String] the URI as a String
# File lib/git/url.rb, line 119 def to_s if user "#{user}@#{host}:#{path[1..-1]}" else "#{host}:#{path[1..-1]}" end end