Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

env_config

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env_config

  • 0.2.0
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

EnvConfig

Simple configuration management with environment variables.

Inspired by how Heroku uses environment variables for configs, EnvConfig is a no-magic gem for defining configs in yaml, and loading them into environment variables.

Features

  • application.yml can be templated with erb.
  • arbitrary namespaced configuration. e.g. development, qa:mac, integration/aws/ci.
  • heroku friendly.
  • small library, no additional dependencies

Installation

Install the gem, and initialize the configuation yaml and configuration loader.

gem install env_config

# if using Rails
rake env_config:init

# otherwise
env_config init

Example

First we define the configs we want in a yaml file:

# Each key value pair in this file will be read by EnvConfig and set to an
# environment variable. If an environment variable already exists, then it is
# not overridden by default. See EnvConfig.configure for more options.

# shared variables
common: &common
  env_config1: 'config1_value'
  env_config2: <%= "you can use erb" %>

# environment specifc variables
development:
  <<: *common
  env_config1: 'config1_override'

test:
  <<: *common

# If your app is deployed on Heroku, then production Heroku values will
# override these settings because existing variables are not overridden by
# default. See also: http://devcenter.heroku.com/articles/config-vars
production:
  <<: *common

Then in config/initializers/env_config.rb

EnvConfig.configure do |config|
  # yaml to read default config variables
  config.config_path   = 'config/application.yml'

  # Whether to override a variable that's already defined in an environment
  # variable. Keep to false if using Heroku.
  config.override_env  = false

  # Namespace config values
  # For example, to namespace by platform and rails environment
  # 
  #   config.namespace_by = "{RbConfig::CONFIG['host_os']}/#{Rails.env}"
  #
  # Then in your config/application.yml, you can nest your config by the
  # namepaces.
  # 
  #   darwin11.0.0:
  #     development:
  #       var_name: "mac development specific value"
  # 
  config.namespace_by  = Rails.env

  # Delimiter to split namespaces by when finding scoped config
  config.namespace_delimiter = '/'
end

# This actually sets the variables into ENV
EnvConfig.set!

From here, you can access any of your variables via ENV:

ENV['my_config_name']

FAQs

Package last updated on 25 Oct 2011

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc