Class: HerokuSan::Stage
Instance Attribute Summary collapse
Instance Method Summary
collapse
#ensure_all_workers_running, #ensure_one_worker_running
Methods included from Git
#git_active_branch, #git_clone, #git_named_rev, #git_parsed_tag, #git_push, #git_rev_parse, #git_revision, #git_tag
Constructor Details
#initialize(stage, options = {}) ⇒ Stage
Returns a new instance of Stage.
14
15
16
17
|
# File 'lib/heroku_san/stage.rb', line 14
def initialize(stage, options = {})
@name = stage
@options = options
end
|
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
10
11
12
|
# File 'lib/heroku_san/stage.rb', line 10
def name
@name
end
|
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/heroku_san/stage.rb', line 11
def options
@options
end
|
Instance Method Details
#==(other) ⇒ Object
19
20
21
|
# File 'lib/heroku_san/stage.rb', line 19
def ==(other)
other.name == name && other.options == options
end
|
#addons ⇒ Object
47
48
49
|
# File 'lib/heroku_san/stage.rb', line 47
def addons
(@options['addons'] ||= []).flatten
end
|
#app ⇒ Object
27
28
29
|
# File 'lib/heroku_san/stage.rb', line 27
def app
@options['app'] or raise MissingApp, "#{name}: is missing the app: configuration value. I don't know what to access on Heroku."
end
|
#config ⇒ Object
43
44
45
|
# File 'lib/heroku_san/stage.rb', line 43
def config
@options['config'] ||= {}
end
|
#create ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/heroku_san/stage.rb', line 88
def create
params = {
'name' => @options['app'],
'stack' => @options['stack']
}
response = heroku.post_app(params)
response.body['name']
end
|
#deploy(commit = nil, force = nil) ⇒ Object
65
66
67
68
|
# File 'lib/heroku_san/stage.rb', line 65
def deploy(commit = nil, force = nil)
strategy = @options['deploy'].new(self, commit, force)
strategy.deploy
end
|
#heroku ⇒ Object
23
24
25
|
# File 'lib/heroku_san/stage.rb', line 23
def heroku
@heroku ||= HerokuSan::API.new(:api_key => auth_token, :mock => MOCK)
end
|
#install_addons ⇒ Object
118
119
120
121
122
123
124
|
# File 'lib/heroku_san/stage.rb', line 118
def install_addons
addons_to_install = addons - installed_addons.map{|a|a['name']}
addons_to_install.each do |addon|
heroku.post_addon(app, addon)
end
installed_addons
end
|
#installed_addons ⇒ Object
114
115
116
|
# File 'lib/heroku_san/stage.rb', line 114
def installed_addons
heroku.get_addons(app).body
end
|
#logs(tail = false) ⇒ Object
130
131
132
|
# File 'lib/heroku_san/stage.rb', line 130
def logs(tail = false)
sh_heroku 'logs', (tail ? '--tail' : nil)
end
|
#long_config ⇒ Object
105
106
107
|
# File 'lib/heroku_san/stage.rb', line 105
def long_config
heroku.get_config_vars(app).body
end
|
#maintenance(action = nil) ⇒ Object
74
75
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/heroku_san/stage.rb', line 74
def maintenance(action = nil)
if block_given?
heroku.post_app_maintenance(app, '1')
begin
yield
ensure
heroku.post_app_maintenance(app, '0')
end
else
raise ArgumentError, "Action #{action.inspect} must be one of (:on, :off)", caller if ![:on, :off].include?(action)
heroku.post_app_maintenance(app, {:on => '1', :off => '0'}[action])
end
end
|
#migrate ⇒ Object
60
61
62
63
|
# File 'lib/heroku_san/stage.rb', line 60
def migrate
run('rake db:migrate')
restart
end
|
#push(sha = nil, force = false) ⇒ Object
55
56
57
58
|
# File 'lib/heroku_san/stage.rb', line 55
def push(sha = nil, force = false)
sha ||= git_parsed_tag(tag)
git_push(sha, repo, force ? %w[--force] : [])
end
|
#push_config(options = nil) ⇒ Object
109
110
111
112
|
# File 'lib/heroku_san/stage.rb', line 109
def push_config(options = nil)
params = (options || config)
heroku.put_config_vars(app, params).body
end
|
#rake(*args) ⇒ Object
70
71
72
|
# File 'lib/heroku_san/stage.rb', line 70
def rake(*args)
raise HerokuSan::Deprecated.new("use Stage#run instead")
end
|
#repo ⇒ Object
31
32
33
|
# File 'lib/heroku_san/stage.rb', line 31
def repo
@options['repo'] ||= "[email protected]:#{app}.git"
end
|
#restart ⇒ Object
126
127
128
|
# File 'lib/heroku_san/stage.rb', line 126
def restart
"restarted" if heroku.post_ps_restart(app).body == 'ok'
end
|
#revision ⇒ Object
134
135
136
|
# File 'lib/heroku_san/stage.rb', line 134
def revision
git_named_rev(git_revision(repo))
end
|
#run(command, args = nil) ⇒ Object
51
52
53
|
# File 'lib/heroku_san/stage.rb', line 51
def run(command, args = nil)
sh_heroku "run", command, *args
end
|
#sharing_add(email) ⇒ Object
97
98
99
|
# File 'lib/heroku_san/stage.rb', line 97
def sharing_add(email)
raise HerokuSan::Deprecated
end
|
#sharing_remove(email) ⇒ Object
101
102
103
|
# File 'lib/heroku_san/stage.rb', line 101
def sharing_remove(email)
raise HerokuSan::Deprecated
end
|
#stack ⇒ Object
35
36
37
|
# File 'lib/heroku_san/stage.rb', line 35
def stack
@options['stack'] ||= heroku.get_stack(app).body.detect{|stack| stack['current']}['name']
end
|
#tag ⇒ Object
39
40
41
|
# File 'lib/heroku_san/stage.rb', line 39
def tag
@options['tag']
end
|