Project

fastenv

0.0
No commit activity in last 3 years
No release in over 3 years
Takes advantage of method_missing to give you fast access to environment variables.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.7
~> 10.0
>= 0
 Project Readme

Fastenv

Gem Version Build Status Code Climate Dependency Status

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.

Installation

Add this line to your application's Gemfile:

gem 'fastenv'

And then execute:

$ bundle

Or install it yourself as:

$ gem install fastenv

Usage

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.

Defaults

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"

Goes Well With

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"}

Contributing

  1. Fork it ( https://github.com/kyletolle/fastenv/fork )
  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 a new Pull Request