Code Monkey home page Code Monkey logo

envyable's Introduction

Envyable

The simplest yaml to ENV config loader.

Gem version Build Status Code Climate

Installation

Add this line to your application's Gemfile:

gem 'envyable'

And then execute:

$ bundle

Or install it yourself as:

$ gem install envyable

Install task

Once the gem is included in your project, you can then use it to generate the default required files. Just run:

$ envyable install

and you will get a config directory containing an env.yml and a env.yml.example file. If you have a .gitignore file this will also append the line:

/config/env.yml

to your config so that you do not check in /config/env.yml.

If you have Spring bundled with your application this will append the following line to /config/spring.rb:

Spring.watch 'config/env.yml'

If the file /config/spring.rb does not exist, it will be created.

Usage

YAML file

Create a yaml file that holds your settings. You can put default settings into the root of the yaml file and then override those on an environment by environment basis. For example, the following yaml file will load the id "development-id" into all environments it is loaded in except for the test environment, where the id would be "test-id".

API_CLIENT_ID: development-id
test:
  API_CLIENT_ID: test-id

Rails

Once installed in a Rails app, add your yaml file at config/env.yml. The gem will load the correct environment on initialization of the application. If you are using Spring to load your Rails application, add config/env.yml to Spring's watch list.

Load Immediately

If you have gems that require variables to be set earlier then place envyable in the Gemfile before those gems and require envyable/rails-now:

gem 'envyable', require: 'envyable/rails-now'
gem 'other-gem-that-requires-env-variables'

Other applications

With the exception of loading Envyable immediately via the Gemfile, you can create your yaml file anywhere (though why not config/env.yml?). To load your yaml file into ENV, call:

Envyable.load('path/to/yml', environment)

The default environment is development if you leave that argument blank. For example, if your variables are in a config folder in a file called env.yml, and you want to load development only, include in your script:

require 'envyable'
Envyable.load('config/env.yml')

Version control

It is not recommended that you check the yaml file in to version control. Personally, I like to check in a env.yml.example file that shows the required keys, but does not include any credentials. If you generate your Envyable files using the installer, config/env.yml will be added to your .gitignore file.

Troubleshooting

If your ENV values don't update when you modify config/env.yml, verify whether you have Spring (or another application preloader) that isn't configured to watch and reload when you update values. You should try configuring the preloader or just restarting it.

Contributing

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

envyable's People

Contributors

mikelkew avatar omnilord avatar philnash avatar siakaramalegos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

envyable's Issues

`envyable install` fails on vanilla install

I've been trying out Envyable for a couple of hours and have been running into a number of problems. I am still trying to document a larger problem, but I found this one while working on that.

Fairly straight forward, running envyable install (with or without Rails) results in this error message. Tried locally on a Mac, and again on a fresh install of ruby and rails on an Ubuntu server, both with the same results.

[02:56 ubuntu@server:~/projects/env_test]$ envyable install
 /home/ubuntu/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- ./lib/envyable/cli (LoadError)
    from /home/ubuntu/.rbenv/versions/2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/ubuntu/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/envyable-1.1.0/bin/envyable:4:in `<top (required)>'
    from /home/ubuntu/.rbenv/versions/2.3.1/bin/envyable:23:in `load'
    from /home/ubuntu/.rbenv/versions/2.3.1/bin/envyable:23:in `\<main\>'

Envyable version 1.1.0

Mac has Ruby 2.3.0, Rails 4.2.6
Ubuntu has Ruby 2.3.1, Rails 5.0.0.1

Create a binary with an export task for Heroku

Export task:

  • Initially will be able to export all config vars in production group of yml file to Heroku
  • Can choose environment exporting
  • Should be able to pass through other options (app name, for example) to heroku command.

Option to load variables earlier for other gems that require them

Hi! We have another gem that requires some ENV variable to be set before it is loaded.

The dotenv gem gives an option of specifying , :require => 'dotenv/rails-now' in the gemfile to load them earlier.. Was just wondering if you can think of a similar way of achieving this with envyable? If not, could you please consider adding it?

`envyable install` error - Cannot load ./lib/envyable/cli

Ran envyable install got the following error:

/Users/michael/.rvm/gems/ruby-2.3.1/gems/envyable-1.1.0/bin/envyable:4:in `require': cannot load such file -- ./lib/envyable/cli (LoadError)
	from /Users/michael/.rvm/gems/ruby-2.3.1/gems/envyable-1.1.0/bin/envyable:4:in `<top (required)>'
	from /Users/michael/.rvm/gems/ruby-2.3.1/bin/envyable:23:in `load'
	from /Users/michael/.rvm/gems/ruby-2.3.1/bin/envyable:23:in `<main>'
	from /Users/michael/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `eval'
	from /Users/michael/.rvm/gems/ruby-2.3.1/bin/ruby_executable_hooks:15:in `<main>'

Changed file bin/envyable to require_relative "../lib/envyable/cli" (had been require "./lib/envyable/cli")

envyable install now working...

Not sure why this happened, because when I cloned the repo and went to edit the code to fix it, it seems someone has very sensibly put require File.expand_path('../lib/envyable/cli', __dir__)

Is gem install envyable installing an old version of the gem?? Confused...

Create a binary with an install task.

Install task:

  • Create config/ folder if it doesn't exist
  • Create config/env.yml and config/env.yml.example
  • If .gitignore exists, add config/env.yml to it

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.