class Paratrooper::HerokuWrapper

Attributes

api_key[R]
app_name[R]
heroku_api[R]
key_extractor[R]
rendezvous[R]

Public Class Methods

new(app_name, options = {}) click to toggle source
# 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

Public Instance Methods

app_maintenance_off() click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 29
def app_maintenance_off
  client(:app, :update, app_name, 'maintenance' => 'false')
end
app_maintenance_on() click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 33
def app_maintenance_on
  client(:app, :update, app_name, 'maintenance' => 'true')
end
app_restart() click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 25
def app_restart
  client(:dyno, :restart_all, app_name)
end
last_deploy_commit() click to toggle source
# 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_slug() click to toggle source
# 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
releases() click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 37
def releases
  @releases ||= client(:release, :list, app_name)
end
run_migrations() click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 41
def run_migrations
  run_task('rake db:migrate')
end
run_task(task) click to toggle source
# 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

Private Instance Methods

client(delegatee, method, *args) click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 68
def client(delegatee, method, *args)
  heroku_api.public_send(delegatee).public_send(method, *args)
rescue Excon::Errors::Forbidden => e
  raise ErrorNoAccess.new(app_name)
end
get_slug_id(release) click to toggle source
# File lib/paratrooper/heroku_wrapper.rb, line 64
def get_slug_id(release)
  release["slug"]["id"]
end