Class: Paratrooper::HerokuWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/paratrooper/heroku_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, options = {}) ⇒ HerokuWrapper

Returns a new instance of HerokuWrapper.



9
10
11
12
13
14
15
# File 'lib/paratrooper/heroku_wrapper.rb', line 9

def initialize(app_name, options = {})
  @app_name      = app_name
  @key_extractor = options[:key_extractor] || LocalApiKeyExtractor
  @api_key       = options[:api_key] || key_extractor.get_credentials
  @heroku_api    = options[:heroku_api] || Heroku::API.new(api_key: api_key)
  @rendezvous    = options[:rendezvous] || Rendezvous
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



7
8
9
# File 'lib/paratrooper/heroku_wrapper.rb', line 7

def api_key
  @api_key
end

#app_nameObject (readonly)

Returns the value of attribute app_name.



7
8
9
# File 'lib/paratrooper/heroku_wrapper.rb', line 7

def app_name
  @app_name
end

#heroku_apiObject (readonly)

Returns the value of attribute heroku_api.



7
8
9
# File 'lib/paratrooper/heroku_wrapper.rb', line 7

def heroku_api
  @heroku_api
end

#key_extractorObject (readonly)

Returns the value of attribute key_extractor.



7
8
9
# File 'lib/paratrooper/heroku_wrapper.rb', line 7

def key_extractor
  @key_extractor
end

#rendezvousObject (readonly)

Returns the value of attribute rendezvous.



7
8
9
# File 'lib/paratrooper/heroku_wrapper.rb', line 7

def rendezvous
  @rendezvous
end

Instance Method Details

#app_maintenance_offObject



21
22
23
# File 'lib/paratrooper/heroku_wrapper.rb', line 21

def app_maintenance_off
  app_maintenance('0')
end

#app_maintenance_onObject



25
26
27
# File 'lib/paratrooper/heroku_wrapper.rb', line 25

def app_maintenance_on
  app_maintenance('1')
end

#app_restartObject



17
18
19
# File 'lib/paratrooper/heroku_wrapper.rb', line 17

def app_restart
  heroku_api.post_ps_restart(app_name)
end

#app_urlObject



29
30
31
# File 'lib/paratrooper/heroku_wrapper.rb', line 29

def app_url
  app_domain_name
end

#last_deploy_commitObject



42
43
44
45
46
# File 'lib/paratrooper/heroku_wrapper.rb', line 42

def last_deploy_commit
  data = heroku_api.get_releases(app_name).body
  return nil if data.empty?
  data.last['commit']
end

#run_migrationsObject



33
34
35
# File 'lib/paratrooper/heroku_wrapper.rb', line 33

def run_migrations
  run_task('rake db:migrate')
end

#run_task(task_name) ⇒ Object



37
38
39
40
# File 'lib/paratrooper/heroku_wrapper.rb', line 37

def run_task(task_name)
  data = heroku_api.post_ps(app_name, task_name, attach: 'true').body
  rendezvous.start(url: data['rendezvous_url'])
end