Class: Git::GitAltURI
- Inherits:
-
Addressable::URI
- Object
- Addressable::URI
- Git::GitAltURI
- Defined in:
- lib/git/url.rb
Overview
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
-
#initialize(user:, host:, path:) ⇒ GitAltURI
constructor
Create a new GitAltURI object.
-
#to_s ⇒ String
Convert the URI to a String.
Constructor Details
#initialize(user:, host:, path:) ⇒ GitAltURI
Create a new GitAltURI object
96 97 98 |
# File 'lib/git/url.rb', line 96 def initialize(user:, host:, path:) super(scheme: 'git-alt', user: user, host: host, path: path) end |
Instance Method Details
#to_s ⇒ String
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:
[email protected]:ruby-git/ruby-git.git
and the following (with the initial '/'' in the path) is NOT a valid git URL:
[email protected]:/ruby-git/ruby-git.git
119 120 121 122 123 124 125 |
# File 'lib/git/url.rb', line 119 def to_s if user "#{user}@#{host}:#{path[1..-1]}" else "#{host}:#{path[1..-1]}" end end |