Class: HustleAndFlow::VersionControls::Git::Commands::Start

Inherits:
Object
  • Object
show all
Defined in:
lib/hustle_and_flow/version_controls/git/commands/start.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ Start

Returns a new instance of Start.



15
16
17
18
19
20
21
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 15

def initialize(**args)
  self.repo            = args[:repo]
  self.io              = args[:io]
  self.number          = args[:number]
  self.title           = args[:title]
  self.branch_template = args[:branch_template]
end

Instance Attribute Details

#branch_templateObject

Returns the value of attribute branch_template.



9
10
11
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 9

def branch_template
  @branch_template
end

#ioObject

Returns the value of attribute io.



9
10
11
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 9

def io
  @io
end

#numberObject

Returns the value of attribute number.



9
10
11
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 9

def number
  @number
end

#repoObject

Returns the value of attribute repo.



9
10
11
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 9

def repo
  @repo
end

#titleObject

Returns the value of attribute title.



9
10
11
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 9

def title
  @title
end

Class Method Details

.call(**args) ⇒ Object



60
61
62
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 60

def self.call(**args)
  new(**args).call
end

Instance Method Details

#callObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/hustle_and_flow/version_controls/git/commands/start.rb', line 23

def call
  available_branches = repo.
                       branches.
                       selectable.
                       filter_by_issue(number: number,
                                       title:  title)

  next_branch_name = available_branches.next_branch_name(template: branch_template)

  selected = if available_branches.count.zero?
               available_branches.create_next_branch(template: branch_template)
             else
               branch_number = nil

               io.print_formatted_table \
                 title: 'Possible Existing Branches',
                 data:  Formatters::BranchTableFormatter.new(available_branches).
                        to_ary

               io.print_new_branch_prompt(next_branch_name)

               until branch_number == 'c' ||
                     available_branches.valid_number?(branch_number)

                 branch_number = io.choose_branch
               end

               if branch_number == 'c'
                 available_branches.create_next_branch(template: branch_template)
               else
                 available_branches.from_number(branch_number)
               end
             end

  selected.start
end