Class: GTA::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/gta/manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = nil) ⇒ Manager

Returns a new instance of Manager.



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

def initialize(config_path = nil)
  @config_path = config_path || "#{Dir.pwd}/config/gta.yml"
end

Instance Attribute Details

#config_pathObject (readonly)

Returns the value of attribute config_path.



3
4
5
# File 'lib/gta/manager.rb', line 3

def config_path
  @config_path
end

Class Method Details

.env_configObject



84
85
86
# File 'lib/gta/manager.rb', line 84

def self.env_config
  ENV['GTA_CONFIG_PATH']
end

.stage_name_errorObject



88
89
90
# File 'lib/gta/manager.rb', line 88

def self.stage_name_error
  "Stage name required. Run rake with argument - `rake:deploy[staging]`"
end

Instance Method Details

#app_nameObject



19
20
21
# File 'lib/gta/manager.rb', line 19

def app_name
  @app_name || config && @app_name
end

#checkout(name) ⇒ Object Also known as: co



27
28
29
30
# File 'lib/gta/manager.rb', line 27

def checkout(name)
  stage!(name).fetch
  stage!(name).checkout
end

#configObject



46
47
48
49
50
51
52
# File 'lib/gta/manager.rb', line 46

def config
  return @config if @config
  parsed = YAML.load(File.read(config_path))
  @app_name = parsed['name']
  @database_config_path = find_database_config(parsed['database_config'])
  @config = parsed['stages']
end

#database_config_pathObject



23
24
25
# File 'lib/gta/manager.rb', line 23

def database_config_path
  @database_config_path || config && @database_config_path
end

#fetchObject



34
35
36
# File 'lib/gta/manager.rb', line 34

def fetch
  stages.each(&:fetch)
end

#fetch!Object



38
39
40
# File 'lib/gta/manager.rb', line 38

def fetch!
  stages.each(&:fetch!)
end

#final_stageObject



70
71
72
# File 'lib/gta/manager.rb', line 70

def final_stage
  stages.detect{|s| s.final? } || stages.last
end

#find_database_config(path) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/gta/manager.rb', line 54

def find_database_config(path)
  if path
    File.dirname(config_path) + "/#{path}"
  else
    LocalDB.default_database_config_path
  end
end

#hotfixer(stage_name = nil) ⇒ Object



74
75
76
77
78
# File 'lib/gta/manager.rb', line 74

def hotfixer(stage_name=nil)
  hotfixers = stages.select{|s| s.hotfixable?}
  default = stage_name == nil ? hotfixers.first : nil
  hotfixers.detect{|s| s.name == stage_name} || default
end

#push_to(name, forced = nil) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/gta/manager.rb', line 9

def push_to(name, forced = nil)
  s = stage!(name)
  fetch!
  if forced == :force
    s.force_push
  else
    s.push
  end
end

#setupObject



42
43
44
# File 'lib/gta/manager.rb', line 42

def setup
  stages.each(&:add_remote)
end

#stage(name) ⇒ Object



66
67
68
# File 'lib/gta/manager.rb', line 66

def stage(name)
  stages.detect{|s| s.name == name.to_s}
end

#stage!(name) ⇒ Object



80
81
82
# File 'lib/gta/manager.rb', line 80

def stage!(name)
  stage(name) || (raise ArgumentError.new("Stage #{name} not found"))
end

#stagesObject



62
63
64
# File 'lib/gta/manager.rb', line 62

def stages
  @stages ||= config.map{ |name, opts| Stage.new(name, self, opts) }
end