Module: URI::Ssh

Extended by:
Ssh
Included in:
Ssh
Defined in:
lib/dr/base/uri.rb

Overview

Defined Under Namespace

Classes: Generic

Instance Method Summary collapse

Instance Method Details

#generic_url?(url) ⇒ Boolean

Returns true if url is https, ssh protocol.

Parameters:

  • url (String)

    git repository-ish url

Returns:

  • (Boolean)

    true if url is https, ssh protocol



50
51
52
53
# File 'lib/dr/base/uri.rb', line 50

def generic_url?(url)
	match = %r{\A(\w*)://}.match(url)
	!match.nil?
end

#internal_parse(uri_string) ⇒ Generic (protected)

Returns parsed object.

Examples:

url = URI::SshGit.parse('[email protected]:packsaddle/ruby-uri-ssh_git.git')
#=> #<URI::SshGit::Generic [email protected]: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

Parameters:

  • url (String)

    git repository url via ssh protocol

Returns:

See Also:



25
26
27
28
29
30
31
# File 'lib/dr/base/uri.rb', line 25

protected def internal_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 || uri_string, path: path_part)
end

#parse(url, force: false) ⇒ URI::Generic, ...

Parameters:

  • url (String)

    git repository-ish url

Returns:

  • (URI::Generic)

    if url starts ssh

  • (URI::HTTPS)

    if url starts https

  • (URI::SshGit)

    if url is ssh+git e.g [email protected]:schacon/ticgit.git



37
38
39
# File 'lib/dr/base/uri.rb', line 37

def parse(url, force: false)
	(ssh_git_url?(url) || force)? URI::Ssh.internal_parse(url) : URI.parse(url)
end

#ssh_git_url?(url) ⇒ Boolean

Parameters:

  • url (String)

    git repository-ish url

Returns:

  • (Boolean)

    true if url is git via ssh protocol



44
45
46
# File 'lib/dr/base/uri.rb', line 44

def ssh_git_url?(url)
	!generic_url?(url)
end