class Object

Constants

ERROR
SUCCESS

Public Instance Methods

connection_options() click to toggle source
# File bin/wait_pg, line 9
def connection_options
  rails_env = ENV.fetch('RAILS_ENV') { 'development' }

  path = File.expand_path('./config/database.yml')
  yaml = YAML.load(ERB.new(File.read(path)).result)[rails_env]

  # Active Record uses it as a default
  return ENV['DATABASE_URL'] unless yaml

  # Set the default adapter (for cases like PostGIS)
  config = yaml['url'].sub(/^.*:\/\//, 'postgres://') if yaml['url']

  config ||= {
    user: yaml['username'],
    host: yaml['host'],
    password: yaml['password'],
    port: yaml['port'],
  }

  config ||= ENV['DATABASE_URL']
end
connection_successful?() click to toggle source
# File bin/wait_pg, line 31
def connection_successful?
  PG::PQPING_OK == PG::Connection.ping(connection_options)
end