Class: Heroku::Helpers::HerokuPostgresql::Resolver

Inherits:
Object
  • Object
show all
Includes:
Heroku::Helpers
Defined in:
lib/heroku/helpers/heroku_postgresql.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Heroku::Helpers

#action, #app_owner, #ask, #confirm, #confirm_command, #create_git_remote, #debug, #debugging?, #default_org_host, #deprecate, #display, #display_header, #display_object, #display_row, #display_table, #error, #error_log, #error_log_path, 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?, #has_git_remote?, #has_http_git_entry_in_netrc, #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, #stderr_print, #stderr_puts, #string_distance, #styled_array, #styled_error, #styled_hash, #styled_header, #suggestion, #time_ago, #truncate, #update_git_remote, #warn_if_using_jruby, #with_tty

Constructor Details

#initialize(app_name, api) ⇒ Resolver

Returns a new instance of Resolver


46
47
48
49
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 46

def initialize(app_name, api)
  @app_name = app_name
  @api = api
end

Instance Attribute Details

#apiObject (readonly)

Returns the value of attribute api


45
46
47
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 45

def api
  @api
end

#app_nameObject (readonly)

Returns the value of attribute app_name


45
46
47
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 45

def app_name
  @app_name
end

Instance Method Details

#all_databasesObject


61
62
63
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 61

def all_databases
  hpg_databases
end

#app_config_varsObject


83
84
85
86
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 83

def app_config_vars
  protect_missing_app
  @app_config_vars ||= api.get_config_vars(app_name).body
end

#database_name_from_url(url) ⇒ Object


65
66
67
68
69
70
71
72
73
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 65

def database_name_from_url(url)
  vars = app_config_vars.reject {|key,value| key == 'DATABASE_URL'}
  if var = vars.invert[url]
    var.gsub(/_URL$/, '')
  else
    uri = URI.parse(url)
    "Database on #{uri.host}:#{uri.port || 5432}#{uri.path}"
  end
end

#hpg_addon_nameObject


75
76
77
78
79
80
81
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 75

def hpg_addon_name
  if ENV['SHOGUN']
    "shogun-#{ENV['SHOGUN']}"
  else
    ENV['HEROKU_POSTGRESQL_ADDON_NAME'] || 'heroku-postgresql'
  end
end

#resolve(identifier, default = nil) ⇒ Object


51
52
53
54
55
56
57
58
59
# File 'lib/heroku/helpers/heroku_postgresql.rb', line 51

def resolve(identifier, default=nil)
  if identifier =~ /::/
    @app_name, db_name = identifier.split('::')
  else
    db_name = identifier
  end

  hpg_resolve(db_name, default)
end