Class: Paratrooper::HerokuWrapper

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

Defined Under Namespace

Classes: ErrorNoAccess

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of HerokuWrapper.



17
18
19
20
21
22
23
# File 'lib/paratrooper/heroku_wrapper.rb', line 17

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] || PlatformAPI.connect_oauth(api_key)
  @rendezvous    = options[:rendezvous] || Rendezvous
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



15
16
17
# File 'lib/paratrooper/heroku_wrapper.rb', line 15

def api_key
  @api_key
end

#app_nameObject (readonly)

Returns the value of attribute app_name.



15
16
17
# File 'lib/paratrooper/heroku_wrapper.rb', line 15

def app_name
  @app_name
end

#heroku_apiObject (readonly)

Returns the value of attribute heroku_api.



15
16
17
# File 'lib/paratrooper/heroku_wrapper.rb', line 15

def heroku_api
  @heroku_api
end

#key_extractorObject (readonly)

Returns the value of attribute key_extractor.



15
16
17
# File 'lib/paratrooper/heroku_wrapper.rb', line 15

def key_extractor
  @key_extractor
end

#rendezvousObject (readonly)

Returns the value of attribute rendezvous.



15
16
17
# File 'lib/paratrooper/heroku_wrapper.rb', line 15

def rendezvous
  @rendezvous
end

Instance Method Details

#app_maintenance_offObject



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

def app_maintenance_off
  client(:app, :update, app_name, 'maintenance' => 'false')
end

#app_maintenance_onObject



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

def app_maintenance_on
  client(:app, :update, app_name, 'maintenance' => 'true')
end

#app_restartObject



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

def app_restart
  client(:dyno, :restart_all, app_name)
end

#last_deploy_commitObject



51
52
53
54
55
# File 'lib/paratrooper/heroku_wrapper.rb', line 51

def last_deploy_commit
  return nil if last_release_with_slug.nil?
  slug_data = client(:slug, :info, app_name, get_slug_id(last_release_with_slug))
  slug_data['commit']
end

#last_release_with_slugObject



57
58
59
60
# File 'lib/paratrooper/heroku_wrapper.rb', line 57

def last_release_with_slug
  # releases is an enumerator
  releases.to_a.reverse.detect { |release| not release['slug'].nil? }
end

#releasesObject



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

def releases
  @releases ||= client(:release, :list, app_name)
end

#run_migrationsObject



41
42
43
# File 'lib/paratrooper/heroku_wrapper.rb', line 41

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

#run_task(task) ⇒ Object



45
46
47
48
49
# File 'lib/paratrooper/heroku_wrapper.rb', line 45

def run_task(task)
  payload = { 'command' => task, 'attach' => 'true' }
  data    = client(:dyno, :create, app_name, payload)
  rendezvous.start(url: data['attach_url'])
end