Class: Heroku::Command::Base

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/heroku/command/base.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Methods included from Helpers

#action, #app_owner, #ask, #confirm, #confirm_command, #create_git_remote, #default_org_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, error_with_failure, error_with_failure=, extended, extended_into, #fail, #format_bytes, #format_date, #format_error, #format_with_bang, #get_terminal_environment, #git, #has_git?, #home_directory, #hprint, #hputs, included, included_into, #json_decode, #json_encode, #launchy, #line_formatter, #longest, #org?, #org_host, #output_with_bang, #quantify, #redisplay, #retry_on_exception, #run_command, #running_on_a_mac?, #running_on_windows?, #set_buffer, #shell, #spinner, #status, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #with_tty

Constructor Details

- (Base) initialize(args = [], options = {})



17
18
19
20
# File 'lib/heroku/command/base.rb', line 17

def initialize(args=[], options={})
  @args = args
  @options = options
end

Instance Attribute Details

- (Object) args (readonly)

Returns the value of attribute args



14
15
16
# File 'lib/heroku/command/base.rb', line 14

def args
  @args
end

- (Object) options (readonly)

Returns the value of attribute options



15
16
17
# File 'lib/heroku/command/base.rb', line 15

def options
  @options
end

Class Method Details

+ (Object) namespace



10
11
12
# File 'lib/heroku/command/base.rb', line 10

def self.namespace
  self.to_s.split("::").last.downcase
end

Instance Method Details

- (Object) api



70
71
72
# File 'lib/heroku/command/base.rb', line 70

def api
  Heroku::Auth.api
end

- (Object) app



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/heroku/command/base.rb', line 22

def app
  @app ||= if options[:confirm].is_a?(String)
    if options[:app] && (options[:app] != options[:confirm])
      error("Mismatch between --app and --confirm")
    end
    options[:confirm]
  elsif options[:app].is_a?(String)
    options[:app]
  elsif ENV.has_key?('HEROKU_APP')
    ENV['HEROKU_APP']
  elsif app_from_dir = extract_app_in_dir(Dir.pwd)
    app_from_dir
  else
    # raise instead of using error command to enable rescuing when app is optional
    raise Heroku::Command::CommandFailed.new("No app specified.\nRun this command from an app folder or specify which app to use with --app APP.") unless options[:ignore_no_app]
  end
end

- (Object) heroku



78
79
80
# File 'lib/heroku/command/base.rb', line 78

def heroku
  Heroku::Auth.client
end

- (Object) org



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/heroku/command/base.rb', line 40

def org
  @nil = false
  options[:ignore_no_app] = true

  @org ||= if skip_org?
    nil
  elsif options[:org].is_a?(String)
    options[:org]
  elsif options[:personal] || @nil
    nil
  elsif org_from_app = extract_org_from_app
    org_from_app
  else
    response = org_api.get_orgs.body
    default = response['user']['default_organization']
    if default
      options[:using_default_org] = true
      default
    elsif options[:ignore_no_org]
      nil
    else
      # raise instead of using error command to enable rescuing when app is optional
      raise Heroku::Command::CommandFailed.new("No org specified.\nRun this command from an app folder which belongs to an org or specify which org to use with --org ORG.")
    end
  end

  @nil = true if @org == nil
  @org
end

- (Object) org_api



74
75
76
# File 'lib/heroku/command/base.rb', line 74

def org_api
  Heroku::Client::Organizations.api
end