1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-05 08:08:02 +00:00

Add Use dotenv In A Non-Rails Project as a ruby til

This commit is contained in:
jbranchaud
2017-10-03 16:59:49 -05:00
parent d54b358976
commit 4f56d2383a
2 changed files with 28 additions and 1 deletions

View File

@@ -0,0 +1,26 @@
# Use dotenv In A Non-Rails Project
Up to now I've only used [`dotenv`](https://github.com/bkeepers/dotenv) in a
Rails context. It can just as easily be used in a plain old Ruby project.
Install the non-Rails version of the gem.
```bash
$ gem install dotenv
```
Then add the following lines wherever you want `dotenv` included and loaded.
In my case, I want it pulled in as part of my RSpec setup in
`spec_helper.rb`.
```ruby
require 'dotenv'
Dotenv.load
```
Your environment variables declared in `.env` are now accessible via fetches
against the `ENV` object.
```ruby
ENV.fetch('my_env_var')
```