Method: Gitable::URI.parse

Defined in:
lib/gitable/uri.rb

.parse(uri) ⇒ Gitable::URI?

Parse a git repository URI into a URI object.

Parameters:

  • uri (Addressable::URI, #to_str)

    URI of a git repository.

Returns:

  • (Gitable::URI, nil)

    the URI object or nil if nil was passed in.

Raises:

  • (TypeError)

    The uri must respond to #to_str.

  • (Gitable::URI::InvalidURIError)

    When the uri is total rubbish.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitable/uri.rb', line 16

def self.parse(uri)
  return uri if uri.nil? || uri.kind_of?(self)

  # addressable::URI.parse always returns an instance of Addressable::URI.
  add = super # >:( at inconsistency

  if Gitable::ScpURI.scp?(uri)
    Gitable::ScpURI.parse(uri)
  else
    new(add.omit(:password,:query,:fragment).to_hash)
  end
end