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.
12
13
14
15
16
|
# File 'lib/heroku_san/stage.rb', line 12
def initialize(stage, options = {})
@name = stage
@options = options
@heroku = options.delete(:api) || HerokuSan::API.new
end
|
Instance Attribute Details
#heroku ⇒ Object
Returns the value of attribute heroku.
10
11
12
|
# File 'lib/heroku_san/stage.rb', line 10
def heroku
@heroku
end
|
#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.
10
11
12
|
# File 'lib/heroku_san/stage.rb', line 10
def options
@options
end
|
Instance Method Details
#==(other) ⇒ Object
18
19
20
|
# File 'lib/heroku_san/stage.rb', line 18
def ==(other)
other.name == name && other.options == options
end
|
#addons ⇒ Object
42
43
44
|
# File 'lib/heroku_san/stage.rb', line 42
def addons
(@options['addons'] ||= []).flatten
end
|
#app ⇒ Object
22
23
24
|
# File 'lib/heroku_san/stage.rb', line 22
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
38
39
40
|
# File 'lib/heroku_san/stage.rb', line 38
def config
@options['config'] ||= {}
end
|
#create ⇒ Object
83
84
85
86
87
88
89
90
|
# File 'lib/heroku_san/stage.rb', line 83
def create
params = {
'name' => @options['app'],
'stack' => @options['stack']
}
response = heroku.post_app(params)
response.body['name']
end
|
#deploy(commit = nil, force = nil) ⇒ Object
60
61
62
63
|
# File 'lib/heroku_san/stage.rb', line 60
def deploy(commit = nil, force = nil)
strategy = @options['deploy'].new(self, commit, force)
strategy.deploy
end
|
#install_addons ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/heroku_san/stage.rb', line 113
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
109
110
111
|
# File 'lib/heroku_san/stage.rb', line 109
def installed_addons
heroku.get_addons(app).body
end
|
#logs(tail = false) ⇒ Object
125
126
127
|
# File 'lib/heroku_san/stage.rb', line 125
def logs(tail = false)
heroku.sh app, 'logs', (tail ? '--tail' : nil)
end
|
#long_config ⇒ Object
100
101
102
|
# File 'lib/heroku_san/stage.rb', line 100
def long_config
heroku.get_config_vars(app).body
end
|
#maintenance(action = nil) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/heroku_san/stage.rb', line 69
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
55
56
57
58
|
# File 'lib/heroku_san/stage.rb', line 55
def migrate
run('rake db:migrate')
restart
end
|
#push(sha = nil, force = false) ⇒ Object
50
51
52
53
|
# File 'lib/heroku_san/stage.rb', line 50
def push(sha = nil, force = false)
sha ||= git_parsed_tag(tag)
git_push(sha, repo, force ? %w[--force] : [])
end
|
#push_config(options = nil) ⇒ Object
104
105
106
107
|
# File 'lib/heroku_san/stage.rb', line 104
def push_config(options = nil)
params = (options || config)
heroku.put_config_vars(app, params).body
end
|
#rake(*args) ⇒ Object
65
66
67
|
# File 'lib/heroku_san/stage.rb', line 65
def rake(*args)
raise HerokuSan::Deprecated.new("use Stage#run instead")
end
|
#repo ⇒ Object
26
27
28
|
# File 'lib/heroku_san/stage.rb', line 26
def repo
@options['repo'] ||= "[email protected]:#{app}.git"
end
|
#restart ⇒ Object
121
122
123
|
# File 'lib/heroku_san/stage.rb', line 121
def restart
"restarted" if heroku.post_ps_restart(app).body == 'ok'
end
|
#run(command, args = nil) ⇒ Object
46
47
48
|
# File 'lib/heroku_san/stage.rb', line 46
def run(command, args = nil)
heroku.sh app, "run", command, *args
end
|
#sharing_add(email) ⇒ Object
92
93
94
|
# File 'lib/heroku_san/stage.rb', line 92
def sharing_add(email) raise HerokuSan::Deprecated
end
|
#sharing_remove(email) ⇒ Object
96
97
98
|
# File 'lib/heroku_san/stage.rb', line 96
def sharing_remove(email) raise HerokuSan::Deprecated
end
|
#stack ⇒ Object
30
31
32
|
# File 'lib/heroku_san/stage.rb', line 30
def stack
@options['stack'] ||= heroku.get_stack(app).body.detect{|stack| stack['current']}['name']
end
|
#tag ⇒ Object
34
35
36
|
# File 'lib/heroku_san/stage.rb', line 34
def tag
@options['tag']
end
|