Fast access to environment variables. Takes advantage of method_missing to easily return values of environment variable.
Why? Because TYPING_IN_ALL_CAPS isn't fun or readable.
Add this line to your application's Gemfile:
gem 'fastenv'
And then execute:
$ bundle
Or install it yourself as:
$ gem install fastenv
Say you have an environment variable
WORDPRESS_USERNAME="La-de-da-de-da"
You can access it from your Ruby code as simply as
require 'fastenv'
Fastenv.wordpress_username
If the environment variable doesn't exist, a NameError
will be raise.
Fastenv is intended for querying credentials. Missing credentials is an exceptional event.
It can be helpful to specify default values though. You can give Fastenv a block, and, if the environment variable is not set, the block will be evaluated and its value returned.
require 'fastenv'
your_special_value = Fastenv.env_does_not_exist { 'but this is a default' }
=> "but this is a default"
Pair it with dotenv to easily set and retrieve your credentials from environment variables.
# .env
WORDPRESS_USERNAME="TweedleDee"
WORDPRESS_PASSWORD="password"
# your_app.rb
require 'dotenv'
Dotenv.load
require 'fastenv'
credentials = {
username: Fastenv.wordpress_username,
password: Fastenv.wordpress_password }
# => {:username=>"TweedleDee", :password=>"password"}
- Fork it ( https://github.com/kyletolle/fastenv/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request