Class: HustleAndFlow::VersionControls::Git::Branches

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/hustle_and_flow/version_controls/git/branches.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo:, branches:) ⇒ Branches

Returns a new instance of Branches.



13
14
15
16
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 13

def initialize(repo:, branches:)
  self.repo     = repo
  self.branches = branches
end

Instance Attribute Details

#branchesObject

Returns the value of attribute branches.



10
11
12
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 10

def branches
  @branches
end

#repoObject

Returns the value of attribute repo.



10
11
12
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 10

def repo
  @repo
end

Instance Method Details

#create_next_branch(template:) ⇒ Object



38
39
40
41
42
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 38

def create_next_branch(template:)
  branch_name = next_branch_name(template: template)

  repo.find_or_create_branch(branch_name)
end

#eachObject



56
57
58
59
60
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 56

def each
  branches.each do |branch|
    yield branch
  end
end

#filter_by_issue(number:, title:) ⇒ Object



18
19
20
21
22
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 18

def filter_by_issue(number:, title:)
  self.class.new(repo:     repo,
                 branches: (branches_matching_issue_number(number) +
                            branches_matching_issue_title(title)).uniq)
end

#from_number(number) ⇒ Object



30
31
32
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 30

def from_number(number)
  branches[number.to_i - 1]
end

#next_branch_name(template:) ⇒ Object



34
35
36
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 34

def next_branch_name(template:)
  template.sub('*****', next_version_number.to_s)
end

#selectableObject



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 44

def selectable
  tracking_branches = branches.map do |branch|
    branch.name if branch.has_tracking_branch?
  end

  self.class.new(repo:     repo,
                 branches: branches.reject do |branch|
                             branch.remote? &&
                             tracking_branches.include?(branch.name)
                           end)
end

#valid_number?(number) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
27
28
# File 'lib/hustle_and_flow/version_controls/git/branches.rb', line 24

def valid_number?(number)
  return false unless number.to_s.match(/\A\d+\z/)

  (1..branches.count).include?(number.to_i)
end