Project

envoker

0.0
No commit activity in last 3 years
No release in over 3 years
Load environment variables from .env
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 5.8
~> 11.0
~> 0.39
 Project Readme

Envoker Build Status

Load environment variables from .env files.

Installation

Add this line to your application's Gemfile:

gem "envoker"

And then execute:

$ bundle

Or install it yourself as:

$ gem install envoker

Usage

Load your .env file in the application bootstrap process:

# .env
RACK_ENV=development

# boot.rb
require "envoker"

Envoker.load

ENV["RACK_ENV"]
# => "development"

You can use Envoker#overload to override existing values in ENV:

# .env.test
RACK_ENV=test

# boot.rb
# ...

Envoker.overload(".env.test")

ENV["RACK_ENV"]
# => "test"

Multiple Environments

Envoker::Rack adds support for multiple environments:

require "envoker/rack"

Envoker::Rack.load

You should store env vars that are general to all environments in .env, and store specific env vars in .env.<environment>.The default environment is development, but can be changed through ENV["RACK_ENV"].

ENV["RACK_ENV"] = "test"

# This will load `.env` and `.env.test`
Envoker::Rack.load

Settings

This is a common pattern I use in my applications:

require "envoker/rack"

Envoker::Rack.load

module Settings
  def self.fetch(key)
    return ENV.fetch(key) do
      raise(sprintf("ENV[%p] not found", key))
    end
  end

  REDIS_URL = fetch("REDIS_URL")
  SMTP_URL  = fetch("SMTP_URL")
end

Settings::SMTP_URL
# => redis://localhost:6379

Contributing

Fork the project with:

$ git clone https://github.com/frodsan/envoker.git

To install dependencies, use:

$ bundle install

To run the test suite, do:

$ rake test

For bug reports and pull requests use GitHub.

License

Envoker is released under the MIT License.