Class: Twig::GithubRepo
- Inherits:
-
Object
- Object
- Twig::GithubRepo
- Defined in:
- lib/twig/github.rb
Overview
Instance Method Summary collapse
- #github_repo? ⇒ Boolean
-
#initialize {|_self| ... } ⇒ GithubRepo
constructor
A new instance of GithubRepo.
- #origin_url ⇒ Object
- #origin_url_parts ⇒ Object
- #repository ⇒ Object
- #username ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ GithubRepo
Returns a new instance of GithubRepo.
13 14 15 16 17 18 19 20 21 |
# File 'lib/twig/github.rb', line 13 def initialize abort 'Current directory is not a git repository.' unless Twig.repo? if origin_url.empty? || !github_repo? || username.empty? || repository.empty? abort 'This does not appear to be a GitHub repository.' end yield(self) end |
Instance Method Details
#github_repo? ⇒ Boolean
31 32 33 34 35 |
# File 'lib/twig/github.rb', line 31 def github_repo? gh_url_prefix = 'https://github.com' uri = URI.parse(gh_url_prefix) origin_url.include?(uri.host) end |
#origin_url ⇒ Object
23 24 25 |
# File 'lib/twig/github.rb', line 23 def origin_url @origin_url ||= Twig.run('git config remote.origin.url') end |
#origin_url_parts ⇒ Object
27 28 29 |
# File 'lib/twig/github.rb', line 27 def origin_url_parts @origin_url_parts ||= origin_url.split(/[\/:]/) end |
#repository ⇒ Object
41 42 43 |
# File 'lib/twig/github.rb', line 41 def repository @repo ||= origin_url_parts[-1].sub(/\.git$/, '') || '' end |
#username ⇒ Object
37 38 39 |
# File 'lib/twig/github.rb', line 37 def username @username ||= origin_url_parts[-2] || '' end |