class Twig::GithubRepo
Represents a Git repository that is hosted on GitHub. Usage:
Twig::GithubRepo.new do |gh_repo| puts gh_repo.username puts gh_repo.repository end
Public Class Methods
new() { |self| ... }
click to toggle source
# 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
Public Instance Methods
github_repo?()
click to toggle source
# 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()
click to toggle source
# File lib/twig/github.rb, line 23 def origin_url @origin_url ||= Twig.run('git config remote.origin.url') end
origin_url_parts()
click to toggle source
# File lib/twig/github.rb, line 27 def origin_url_parts @origin_url_parts ||= origin_url.split(/[\/:]/) end
repository()
click to toggle source
# File lib/twig/github.rb, line 41 def repository @repo ||= origin_url_parts[-1].sub(/\.git$/, '') || '' end
username()
click to toggle source
# File lib/twig/github.rb, line 37 def username @username ||= origin_url_parts[-2] || '' end