Socket
Book a DemoInstallSign in
Socket

require_env

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

require_env

1.2.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

RequireEnv

Check environment variable presence easily.

Install

bundle install require_env

Usage

Create a YAML file, e.g. config/environment.yml, where you define the environment variables required by your application, for the different environment it will run (test, development, production by default)

  • You can use ERB code to provide computed values
  • You can use YAML defaults.
  • An optional default value can be given for any key
  • Keys ending with _IF_OTHER_VARIABLE will only be checked if OTHER_VARIABLE is defined and not equal 'false'
  • Default value have precedence over the _IF_OTHER_VARIABLE rule

Here is an example presenting the different possibilities:

DEFAULTS: &DEFAULTS
  BEANSTALK_URL: 'beanstalk://127.0.0.1'

  SLACK_TOKEN:

  # Use the environment variable TOKEN_SCALINGO as a default value if provided
  SCALINGO_TOKEN: "<%= ENV['TOKEN_SCALINGO'] %>"

  # Declare STRIPE_ENABLED to check for STRIPE_PUBLIC_KEY and STRIPE_SECRET_KEY
  STRIPE_PUBLIC_KEY_IF_STRIPE_ENABLED:
  STRIPE_SECRET_KEY_IF_STRIPE_ENABLED:

test:
  <<: *DEFAULTS
  IGNORE_EVENT_DELAY: 'true'

development:
  <<: *DEFAULTS
  IGNORE_EVENT_DELAY: 'true'

production:
  <<: *DEFAULTS

When your application starts, simply call RequireEnv.check(Rails.root.join('config', 'environment.yml')) to check if the required environment variables are provided.

If any variable is missing, RequireEnv::Missing will be raised, detailing the missing environment variable.

FAQs

Package last updated on 28 Jun 2017

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.