Class: GTA::Hotfix

Inherits:
Object
  • Object
show all
Includes:
Sh
Defined in:
lib/gta/hotfix.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Sh

#commander, #sh, #sh!

Constructor Details

#initialize(gta_config_path = nil) ⇒ Hotfix

Returns a new instance of Hotfix.



7
8
9
# File 'lib/gta/hotfix.rb', line 7

def initialize(gta_config_path = nil)
  @gta_config_path = gta_config_path
end

Instance Attribute Details

#gta_config_pathObject (readonly)

Returns the value of attribute gta_config_path.



5
6
7
# File 'lib/gta/hotfix.rb', line 5

def gta_config_path
  @gta_config_path
end

Instance Method Details

#branch_nameObject



37
38
39
40
41
# File 'lib/gta/hotfix.rb', line 37

def branch_name
  branches = sh!("git branch").strip
  matches = branches.match(/\*\s+(.*)/)
  matches[1].strip if matches
end

#checkout(stage_name = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/gta/hotfix.rb', line 11

def checkout(stage_name=nil)
  stage = stage_for(stage_name)
  sh!("git fetch #{stage.name}")
  not_hotfixable!(stage_name) unless stage
  stage.checkout
end

#deployObject



22
23
24
25
26
27
# File 'lib/gta/hotfix.rb', line 22

def deploy
  stage_name = branch_name
  stage = stage_for(stage_name)
  not_hotfixable!(stage_name) if !stage || !stage_name
  sh!("git push #{stage_name} #{stage_name}:master")
end

#managerObject



18
19
20
# File 'lib/gta/hotfix.rb', line 18

def manager
  @manager ||= Manager.new(gta_config_path)
end

#not_hotfixable!(stage_name) ⇒ Object



29
30
31
# File 'lib/gta/hotfix.rb', line 29

def not_hotfixable!(stage_name)
  raise "stage #{stage_name} not hotfixable"
end

#stage_for(stage_name) ⇒ Object



33
34
35
# File 'lib/gta/hotfix.rb', line 33

def stage_for(stage_name)
  manager.hotfixer(stage_name)
end