Skip to content

Latest commit

 

History

History
47 lines (30 loc) · 1.31 KB

README.rdoc

File metadata and controls

47 lines (30 loc) · 1.31 KB

Environment

Depending on how you start a Ruby process, it may not pick up all of the Bash Env Vars. To rectify this, This gem employs two mechanisms. First if tries to load some code from a .env file in the process root dir. Then it fires up a full login shell and sucks out all of the vars.

The final authority is the login shell variables. They will override any conflicts stemming from .env files.

This Gem also purges standard ENV of any Env Vars that start with SEC_ This was added to prevent some debugging tools from leaking secure env vars.

Some code was borrowed from teh dotenv gem project.

Installation

# gem install environment

Usage

The global constant ENV is mostly left untouched by default. The global ENV will be purged of anything matching ^SEC_. To read an environment variable, use Environment.get or Environment[].

Example usage:

require "rubygems"
require "environment"

# the following two are the same
path = Environment['PATH']
home = Environment.get('HOME')

Environment.to_a

If you want to override the default ENV constant, use the override! method ##Warning, this can be full of suprises with some ruby products

Example usage:

require "rubygems"
require "environment"

host = ENV['HOSTNAME'] #nil
Environment.override!
host = ENV['HOSTNAME'] #yourdomain.com