mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 07:08:01 +00:00
Add Use dotenv In A Non-Rails Project as a ruby til
This commit is contained in:
@@ -10,7 +10,7 @@ smart people at [Hashrocket](http://hashrocket.com/).
|
|||||||
For a steady stream of TILs from a variety of rocketeers, checkout
|
For a steady stream of TILs from a variety of rocketeers, checkout
|
||||||
[til.hashrocket.com](https://til.hashrocket.com/).
|
[til.hashrocket.com](https://til.hashrocket.com/).
|
||||||
|
|
||||||
_570 TILs and counting..._
|
_571 TILs and counting..._
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@@ -463,6 +463,7 @@ _570 TILs and counting..._
|
|||||||
- [`undef_method` And The Inheritance Hierarchy](ruby/undef-method-and-the-inheritance-hierarchy.md)
|
- [`undef_method` And The Inheritance Hierarchy](ruby/undef-method-and-the-inheritance-hierarchy.md)
|
||||||
- [Up And Down With Integers](ruby/up-and-down-with-integers.md)
|
- [Up And Down With Integers](ruby/up-and-down-with-integers.md)
|
||||||
- [Use A Case Statement As A Cond Statement](ruby/use-a-case-statement-as-a-cond-statement.md)
|
- [Use A Case Statement As A Cond Statement](ruby/use-a-case-statement-as-a-cond-statement.md)
|
||||||
|
- [Use dotenv In A Non-Rails Project](ruby/use-dotenv-in-a-non-rails-project.md)
|
||||||
- [Who Are My Ancestors?](ruby/who-are-my-ancestors.md)
|
- [Who Are My Ancestors?](ruby/who-are-my-ancestors.md)
|
||||||
- [Zero Padding](ruby/zero-padding.md)
|
- [Zero Padding](ruby/zero-padding.md)
|
||||||
|
|
||||||
|
|||||||
26
ruby/use-dotenv-in-a-non-rails-project.md
Normal file
26
ruby/use-dotenv-in-a-non-rails-project.md
Normal 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')
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user