Class: EasyAuto::CreateBranch

Inherits:
Object
  • Object
show all
Includes:
EasyUtilities, GitWrapper
Defined in:
lib/easy_auto/create_branch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from EasyUtilities

#ask, #hidden_input

Methods included from GitWrapper

#git

Constructor Details

#initialize(new_branch = nil, origin_branch = nil) ⇒ CreateBranch

Returns a new instance of CreateBranch.



12
13
14
15
# File 'lib/easy_auto/create_branch.rb', line 12

def initialize new_branch = nil, origin_branch = nil
  @new_branch = new_branch
  @origin_branch = origin_branch
end

Instance Attribute Details

#new_branchObject (readonly)

Returns the value of attribute new_branch.



9
10
11
# File 'lib/easy_auto/create_branch.rb', line 9

def new_branch
  @new_branch
end

#origin_branchObject (readonly)

Returns the value of attribute origin_branch.



10
11
12
# File 'lib/easy_auto/create_branch.rb', line 10

def origin_branch
  @origin_branch
end

Instance Method Details

#checkout_masterObject



37
38
39
# File 'lib/easy_auto/create_branch.rb', line 37

def checkout_master
  git.checkout_master
end

#help_request?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/easy_auto/create_branch.rb', line 29

def help_request?
  %w{-h --help}.include? new_branch
end

#new_branch_messageObject



49
50
51
# File 'lib/easy_auto/create_branch.rb', line 49

def new_branch_message
  puts "successfully created branch and set upstream remote!"
end

#pullObject



41
42
43
# File 'lib/easy_auto/create_branch.rb', line 41

def pull
  git.pull
end

#runObject



17
18
19
20
21
22
23
# File 'lib/easy_auto/create_branch.rb', line 17

def run
  return usage if wrong_usage || help_request?
  checkout_master
  pull
  git.create_and_switch_to new_branch, origin_branch
  new_branch_message if set_upstream
end

#set_upstreamObject



45
46
47
# File 'lib/easy_auto/create_branch.rb', line 45

def set_upstream
  SetUpstream.new(new_branch).set
end

#usageObject



33
34
35
# File 'lib/easy_auto/create_branch.rb', line 33

def usage
  puts 'usage: create-branch <new-branch> <OPTIONAL: branch-to-track>.'
end

#wrong_usageObject



25
26
27
# File 'lib/easy_auto/create_branch.rb', line 25

def wrong_usage
  [new_branch, origin_branch].all?(&:nil?)
end