Socket
Book a DemoInstallSign in
Socket

envi

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envi

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

Envy Build Status

Envy is a simple module to define environment variable requirements, and to load those environment variables into Ruby constants. This is ideal for managing configuration settings using environment variables, as one would on Heroku.

Read the full API documentation for detailed API and usage instructions.

Installation

Add this line to your application's Gemfile:

gem 'envy'

And then execute:

% bundle

Or install it yourself as:

% gem install envy

Usage

The envars.yml file

First, define your requirements in a YAML file. By default, Envy will look for ./config/envars.yml. For example:

---
&defaults:
  - name: AWS_ACCESS_KEY
    message: Please provide your Amazon AWS credentials as environment variables.
  - name: AWS_ACCESS_SECRET
    message: Please provide your Amazon AWS credentials as environment variables.
  - name: HASHING_SALT
production:
  <<: *defaults
development:
  <<: *defaults

You can define your required environment variables by name, and also provide an optional custom exception message to be used when that variable is not set.

Initializing Envy

To read the requirements and inspect the current environment variables, simply call Envy.init. This will raise an exception if requirements are not met. When working with Rails apps, you might want to use this is an initializer.

Providing environment variables in a file

A common pattern is to define custom environment variables in a .env file in your application's root directory. Other gems, such as [Foreman][] will use such a file to augment the environment before running processes. When in development mode, Envy can also do this for you. Simply tell it which file to use:

Envy.init parse: '.env'

It is a good idea to not include such a file (which commonly contains application secrets) in source control.

Extending your Rails application configuration

Envy will expose all the loaded environment variables as constants in the Envy module, so you can access them as:

Envy::MY_VARIABLE

You could also opt to extend your Rails configuration object:

Envy.init use: MyApp::Application.config
MyApp::Application.config.my_variable # => ...

Contributing

  • Fork it
  • 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 new Pull Request

FAQs

Package last updated on 14 Jun 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.