Class: HerokuSan::API

Inherits:
Object
  • Object
show all
Defined in:
lib/heroku_san/api.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ API

Returns a new instance of API.



5
6
7
# File 'lib/heroku_san/api.rb', line 5

def initialize(options = {})
  @options = options
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/heroku_san/api.rb', line 23

def method_missing(name, *args)
  heroku_api.send(name, *args)
rescue Heroku::API::Errors::ErrorWithResponse => error
  status = error.response.headers["Status"]
  msg = JSON.parse(error.response.body)['error'] rescue '???'
  error.set_backtrace([])
  $stderr.puts "\nHeroku API ERROR: #{status} (#{msg})\n\n"
  raise error
end

Instance Method Details

#sh(app, *command) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/heroku_san/api.rb', line 9

def sh(app, *command)
  preflight_check_for_cli

  cmd = (command + ['--app', app, "--exit-code"]).compact

  show_command = cmd.join(' ')
  $stderr.puts show_command if @debug

  ok = Bundler.with_clean_env { system "heroku", *cmd }

  status = $?
  ok or fail "Command failed with status (#{status.exitstatus}): [heroku #{show_command}]"
end