class Sleet::LocalRepo
Constants
- CURRENT_BRANCH_REGEX
- GITHUB_MATCH_REGEX
- REMOTE_BRANCH_REGEX
Attributes
source_dir[R]
Public Class Methods
new(source_dir:)
click to toggle source
# File lib/sleet/local_repo.rb, line 9 def initialize(source_dir:) @source_dir = source_dir end
Public Instance Methods
branch_name()
click to toggle source
# File lib/sleet/local_repo.rb, line 25 def branch_name validate! current_branch.upstream.name.match(REMOTE_BRANCH_REGEX)[2] end
project()
click to toggle source
# File lib/sleet/local_repo.rb, line 19 def project validate! github_match[2] end
username()
click to toggle source
# File lib/sleet/local_repo.rb, line 13 def username validate! github_match[1] end
Private Instance Methods
current_branch()
click to toggle source
# File lib/sleet/local_repo.rb, line 39 def current_branch @current_branch ||= repo.branches[current_branch_name] end
current_branch_name()
click to toggle source
# File lib/sleet/local_repo.rb, line 35 def current_branch_name @current_branch_name ||= repo.head.name.sub(CURRENT_BRANCH_REGEX, '') end
github_match()
click to toggle source
# File lib/sleet/local_repo.rb, line 43 def github_match @github_match ||= GITHUB_MATCH_REGEX.match(current_branch.remote.url) end
must_be_on_branch!()
click to toggle source
# File lib/sleet/local_repo.rb, line 60 def must_be_on_branch! !current_branch.nil? || raise(Error, 'Not on a branch') end
must_have_an_upstream_branch!()
click to toggle source
# File lib/sleet/local_repo.rb, line 65 def must_have_an_upstream_branch! !current_branch.remote.nil? || raise(Error, "No upstream branch set for the current branch of #{current_branch_name}") end
repo()
click to toggle source
# File lib/sleet/local_repo.rb, line 47 def repo @repo ||= Rugged::Repository.new(source_dir) end
upstream_remote_must_be_github!()
click to toggle source
# File lib/sleet/local_repo.rb, line 70 def upstream_remote_must_be_github! !github_match.nil? || raise(Error, 'Upstream remote is not GitHub') end
validate!()
click to toggle source
# File lib/sleet/local_repo.rb, line 51 def validate! return if @validated must_be_on_branch! must_have_an_upstream_branch! upstream_remote_must_be_github! @validated = true end