Class: Gitable::ScpURI
- Defined in:
- lib/gitable/scp_uri.rb
Constant Summary collapse
- REGEXP =
%r|^([^:/?#]+):([^:?#]*)$|
Class Method Summary collapse
-
.parse(uri) ⇒ Gitable::URI?
Parse an Scp style git repository URI into a URI object.
-
.scp?(uri) ⇒ Boolean
Expected to be an scp style URI if Addressable interprets it wrong and it matches our scp regexp.
Instance Method Summary collapse
-
#inferred_scheme ⇒ String
Return the actual scheme even though we don’t show it.
-
#path=(new_path) ⇒ String
Keep URIs like this as they were input:.
-
#ssh? ⇒ true
Scp style URIs are always ssh.
-
#to_s ⇒ String
Get the URI as a string in the same form it was input.
Methods inherited from URI
#authenticated?, #basename, #basename=, #extname=, #github?, heuristic_parse, #local?, #project_name, #set_git_extname, #to_web_uri
Class Method Details
.parse(uri) ⇒ Gitable::URI?
Parse an Scp style git repository URI into a URI object.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gitable/scp_uri.rb', line 26 def self.parse(uri) return uri if uri.nil? || uri.kind_of?(self) if scp?(uri) , path = uri.scan(REGEXP).flatten Gitable::ScpURI.new(:authority => , :path => path) else raise InvalidURIError, "Unable to parse scp style URI: #{uri}" end end |
.scp?(uri) ⇒ Boolean
Expected to be an scp style URI if Addressable interprets it wrong and it matches our scp regexp
nil host is an Addressable misunderstanding (therefore it might be scp style)
12 13 14 |
# File 'lib/gitable/scp_uri.rb', line 12 def self.scp?(uri) uri && uri.match(REGEXP) && Addressable::URI.parse(uri).normalized_host.nil? end |
Instance Method Details
#inferred_scheme ⇒ String
Return the actual scheme even though we don’t show it
77 78 79 |
# File 'lib/gitable/scp_uri.rb', line 77 def inferred_scheme 'ssh' end |
#path=(new_path) ⇒ String
Keep URIs like this as they were input:
git@github.com:martinemde/gitable.git
Without breaking URIs like these:
[email protected]:/home/martinemde/gitable.git
48 49 50 51 52 53 54 55 56 |
# File 'lib/gitable/scp_uri.rb', line 48 def path=(new_path) super if new_path[0..0] != '/' # addressable adds a / but scp-style uris are altered by this behavior @path = path.sub(%r|^/+|,'') @normalized_path = normalized_path.sub(%r|^/+|,'') validate end path end |
#ssh? ⇒ true
Scp style URIs are always ssh
84 85 86 |
# File 'lib/gitable/scp_uri.rb', line 84 def ssh? true end |
#to_s ⇒ String
Get the URI as a string in the same form it was input.
Taken from Addressable::URI.
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/gitable/scp_uri.rb', line 63 def to_s @uri_string ||= begin uri_string = "#{}:#{normalized_path}" if uri_string.respond_to?(:force_encoding) uri_string.force_encoding(Encoding::UTF_8) end uri_string end end |