Class: Chandler::GitHub::Remote
- Inherits:
-
Object
- Object
- Chandler::GitHub::Remote
- Defined in:
- lib/chandler/github/remote.rb
Overview
Assuming a git remote points to a public GitHub or a GitHub Enterprise repository, this class parses the remote to obtain the host and repository path. Supports SSH and HTTPS style git remotes.
This class also handles parsing values passed into the ‘–github` command line option, which may be a public GitHub repository name, like “mattbrictson/chandler”.
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
Returns the value of attribute host.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(host, path) ⇒ Remote
constructor
A new instance of Remote.
- #repository ⇒ Object
Constructor Details
#initialize(host, path) ⇒ Remote
Returns a new instance of Remote.
27 28 29 30 |
# File 'lib/chandler/github/remote.rb', line 27 def initialize(host, path) @host = host.downcase @path = path end |
Instance Attribute Details
#host ⇒ Object (readonly)
Returns the value of attribute host.
25 26 27 |
# File 'lib/chandler/github/remote.rb', line 25 def host @host end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/chandler/github/remote.rb', line 25 def path @path end |
Class Method Details
.parse(url) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/chandler/github/remote.rb', line 14 def self.parse(url) if (match = url.match(/@([^:]+):(.+)$/)) new(match[1], match[2]) else parsed_uri = URI(url) host = parsed_uri.host || "github.com" path = parsed_uri.path.sub(%r{^/+}, "") new(host, path) end end |
Instance Method Details
#repository ⇒ Object
32 33 34 |
# File 'lib/chandler/github/remote.rb', line 32 def repository path.sub(/\.git$/, "") end |