https://github.com/fuseraft/envl
A simple environment variable loader that reads .env files.
https://github.com/fuseraft/envl
Last synced: about 1 year ago
JSON representation
A simple environment variable loader that reads .env files.
- Host: GitHub
- URL: https://github.com/fuseraft/envl
- Owner: fuseraft
- Created: 2023-02-12T05:02:31.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-02-15T21:01:37.000Z (over 3 years ago)
- Last Synced: 2025-03-27T07:24:51.259Z (about 1 year ago)
- Language: Ruby
- Homepage:
- Size: 12.7 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Envl (.env loader)
A simple environment variable loader that reads `.env` files into [`ENV`](https://docs.ruby-lang.org/en/master/ENV.html).
You can find the gem here: [Envl](https://rubygems.org/gems/envl)
# Installation
```
gem install envl
```
# Basic usage
Add a `require` to your `.rb` file and call `Envl#auto_load`.
```ruby
require 'envl'
# Automatically load .env file in current directory into ENV
Envl.auto_load
# Now we have a happy ENV!
Envl.keys.each {|v| puts "#{v}: #{ENV[v]}"}
```
# Methods
`Envl#auto_load`: Finds and loads `.env` files in the current directory into `ENV`.
`Envl#keys`: Returns all keys loaded into `ENV` via `Envl`.
`Envl#load`: Loads an array of `.env` files into `ENV`.
`Envl#load_path`: Finds and loads `.env` files in a specific directory into `ENV`.
`Envl#load_single`: Loads a single `.env` file into `ENV`.
# More examples
Automatically loading `.env` files (if any exist in the current directory) into `ENV`.
```ruby
Envl.auto_load
```
Loading multiple `.env` files into `ENV`.
```ruby
Envl.load(['../app.env', 'settings.env'])
```
Loading `.env` files in a specific directory into `ENV`.
```ruby
Envl.load_path('..')
```
Loading a single specific `.env` file into `ENV`.
```ruby
Envl.load_single('../app.env')
```
Printing all loaded keys and values in `ENV` loaded by `Envl`.
```ruby
Envl.auto_load
Envl.keys.each {|v| puts "#{v}: #{ENV[v]}"}
```