Ruby gem for storing and obtaining the database parameters
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This Ruby Gem is used for storing the database name, username, and password. It is designed to work for the development and production environment.

Please note that the procedures in this document assume that you are using a PostgreSQL database. For other databases, the commands for creating a database and giving your username full access to it will be different.

This gem will NOT work if the database name and the path to the file storing this information are not provided.

When this gem is used to access a database, it will initially assume that it is in the production environment. If this assumption does not appear to be valid, it will assume that it is in the development environment instead.
If the database username and password are not provided in the expected files in the production environment, this gem will be unable to access the database.


Add this line to your application's Gemfile:

gem 'database_params'

And then execute:

$ bundle

Or install it yourself as:

$ gem install database_params


  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Usage (Development Environment)

  1. Create the PostgreSQL database and make yourself a superuser. The commands for doing this are as follows: sudo su postgres -c psql CREATE ROLE [OS username] SUPERUSER LOGIN; \q createdb

  2. Provide the name of the PostgreSQL database and the path of the file in which you wish to store this information. The following command carries out the task: DatabaseParams.SetDbName([name of database], [path to database name])

  3. To verify the database name that this gem expects to work, enter the following command: puts DatabaseParams.GetDbName([path to database name])

  4. To verify that the gem can access your database username (which should be the same as your regular OS username), enter the following command: puts DatabaseParams.GetDbUsername([path to database name])

  5. To verify that the gem can access your database password (which should not exist), enter the following command: puts DatabaseParams.GetDbPassword([path to database name])

Usage (Production Environment)

  1. You MUST create the PostgreSQL database.

  2. Follow steps 2-3 of the prerequisites for setting up this gem in the development environment.

  3. In your home user directory, create a directory called ".#{db_name}".
    For example, if your home user directory is "/home/wbuffett" and your database name is called "pg_test", you need to create the directory "/home/wbuffett/.pg_test"

  4. Within the ".#{db_name}" directory, store the username for accessing the database in the file ".username", and store the password in the file ".password".

  5. To verify the directory path containing your database username and password, enter the following command: puts DatabaseParams.GetLoginDir

  6. To verify that the gem can access your database username, enter the following command: puts DatabaseParams.GetDbUsername

  7. To verify that the gem can access your database password, enter the following command: puts DatabaseParams.GetDbPassword