Class: Giturl::RemoteUrl
- Inherits:
-
Object
- Object
- Giturl::RemoteUrl
- Defined in:
- lib/giturl/remote_url.rb
Overview
The URL of a git remote, as remote.origin.url reports it, and the https
page that serves the same repository.
A remote is written either as an scp-style address ([email protected]:owner/repo.git) or as a URL carrying a scheme (https://, ssh://, git://). Only the scp-style form can name a Host alias from ~/.ssh/config ([email protected]:owner/repo.git) in place of a real hostname, so that is the only form ssh is asked about.
Constant Summary collapse
- SCHEMED =
%r{\A[a-z][a-z0-9+.-]*://(?:[^@/]*@)?(?<host>[^/:]+)(?::\d+)?/(?<path>.*)\z}i- SCP =
%r{\A(?:[^@/]+@)?(?<host>[^/:]+):(?<path>.*)\z}
Instance Method Summary collapse
-
#https ⇒ String
Anything neither form recognizes is handed back untouched: it names no host, so there is no page to point at.
-
#initialize(raw) ⇒ RemoteUrl
constructor
A new instance of RemoteUrl.
Constructor Details
#initialize(raw) ⇒ RemoteUrl
Returns a new instance of RemoteUrl.
16 17 18 |
# File 'lib/giturl/remote_url.rb', line 16 def initialize(raw) @raw = raw end |
Instance Method Details
#https ⇒ String
Anything neither form recognizes is handed back untouched: it names no host, so there is no page to point at.
24 25 26 27 28 29 30 31 32 |
# File 'lib/giturl/remote_url.rb', line 24 def https schemed = SCHEMED.match(@raw) return page(schemed[:host], schemed[:path]) if schemed scp = SCP.match(@raw) return @raw unless scp page(hostname(scp[:host]) || scp[:host], scp[:path]) end |