• Stars
    star
    7
  • Rank 2,294,772 (Top 46 %)
  • Language
    Crystal
  • License
    MIT License
  • Created almost 5 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Load environment variables from YAML

Envy

Envy loads and sets environment variables from YAML. It supports all YAML data types, including arrays and hashes.

Envy uses the YAML key mapping of a value as the environment variable name. For example, the following YAML configuration...

---
app:
  database:
    host: localhost
    port: 4321
  server:
    hosts:
      - localhost
      - grottopress.localhost
    port: 8080
  webhooks:
    - url: "https://example.com"
      token: "a1b2c2"
    - url: "https://myapp.net"
      token: "d4e5f6"

...sets environment variables as follows:

ENV["APP_DATABASE_HOST"] = "localhost"
ENV["APP_DATABASE_PORT"] = "4321"

ENV["APP_SERVER_HOSTS_0"] = "localhost"
ENV["APP_SERVER_HOSTS_1"] = "grottopress.localhost"
ENV["APP_SERVER_PORT"] = "8080"

ENV["APP_WEBHOOKS_0_URL"] = "https://example.com"
ENV["APP_WEBHOOKS_0_TOKEN"] = "a1b2c2"
ENV["APP_WEBHOOKS_1_URL"] = "https://myapp.net"
ENV["APP_WEBHOOKS_1_TOKEN"] = "d4e5f6"

Envy loads environment variables only once per application life-cycle. This avoids the overhead of reading and parsing YAML files on every single request.

It sets file permission (0600 by default) for all config files.

Envy supports loading a file from a supplied list of files in decreasing order of priority; the first readable file is loaded.

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      envy:
        github: GrottoPress/envy
  2. Run shards install

Usage

  • Load the first readable file from a supplied list of files. Optionally set files permissions. This does not overwrite existing environment variables:

    require "envy"
    
    Envy.from_file ".env.yml", ".env.dev.yml", perm: 0o400
  • Load the first readable file from a supplied list of files. Optionally set files permissions. This overwrites existing environment variables:

    require "envy"
    
    Envy.from_file! ".env.yml", ".env.dev.yml", perm: 0o400

Contributing

  1. Fork it
  2. Switch to the master branch: git checkout master
  3. Create your feature branch: git checkout -b my-new-feature
  4. Make your changes, updating changelog and documentation as appropriate.
  5. Commit your changes: git commit
  6. Push to the branch: git push origin my-new-feature
  7. Submit a new Pull Request against the GrottoPress:master branch.

More Repositories

1

shield

Comprehensive security for Lucky framework
Crystal
55
star
2

mel

A scalable asynchronous event-driven jobs engine
Crystal
36
star
3

pond

Crystal WaitGroups without channels or counters
Crystal
25
star
4

markout

Markout is an awesome Crystal DSL for HTML
Crystal
22
star
5

annotation.cr

Crystal annotations
Crystal
22
star
6

kitty

Kitty is a collection of utilities for SvelteKit
TypeScript
16
star
7

cryflare

A low-level API client for Cloudflare® v4
Crystal
9
star
8

lucille

Utilities for Lucky framework
Crystal
8
star
9

bill

Accounts Receivable automation for Lucky framework
Crystal
8
star
10

jentil

Jentil is a modern framework for rapid WordPress theme development
PHP
6
star
11

pawn

A low-level API client for Pwned Passwords
Crystal
6
star
12

wordpress-field

A library to render form fields in WordPress.
PHP
6
star
13

penny

Get up and running with Lucky framework and Shield
Crystal
5
star
14

simple_ssh

Simple stateless SSH communication
Crystal
5
star
15

haystack

A low-level API client for Paystack
Crystal
5
star
16

samba

Single Sign On authentication for Lucky framework
Crystal
4
star
17

lester

A low-level API client for LXD
Crystal
3
star
18

wordpress-breadcrumbs

A library to render breadcrumbs for a WordPress page.
PHP
3
star
19

guru

[DEPRECATED] See Mel: https://github.com/GrottoPress/mel
Crystal
2
star
20

wordpress-meta-box

A utility to set up meta boxes in WordPress
PHP
1
star
21

hapi

A low-level API client architecture for Crystal
Crystal
1
star
22

jentil-theme

A starter for building WordPress themes with Jentil
PHP
1
star
23

rex

A simple i18n adapter interface for Crystal
Crystal
1
star
24

form-field

A library to render HTML form fields.
PHP
1
star
25

wordpress-suv

A scaffold for implementing the SUV architecture
PHP
1
star
26

wordpress-posts

Query and display posts in WordPress
PHP
1
star
27

halo

SMTP adapter for Carbon mailer
Crystal
1
star