Project

deepenv

0.0
No release in over a year
Generates a deeply nested configuration object suitable for backend apps, using environment variables.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

Deepenv

Best practice demands that configuration that changes across environments should be contained in the environment rather than in code. This helps with security, managing environments, portability and open-source development.

Unfortunately environment variables are flat string key-value pairs, whereas most apps organise their configuration in deeply nested objects. Environment variable names cannot include symbols to indicate nesting.

This means backend developers have to take environment variables such as

MYAPP_MYDATASTORE_CONNECTION_RETRY_INTERVAL=5s

are manually wire them into the configuration object.

Deepenv makes this a lot simpler. EG including deepenv like so:

require "deepenv"

module MyApp
# ...
  class Application < Rails::Application
# ... 
    config.deepenv = Deepenv.to_config()
    print config.deepenv
  end
end

And executing with some double underscore environment variables EG:

 DEEPENV_A__B__C=20 DEEPENV_A__X__Y=ardvark bin/rails server

Shows the deep configuration automatically generated from the environment:

{:a=>{:b=>{:c=>20}, :x=>{:y=>"ardvark"}}}

Installation

Add the deepenv gem:

$ bundle add deepenv

this adds deepenv to your Gemfile and runs bundle install

Usage

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/deepenv. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Deepenv project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.