Socket
Book a DemoInstallSign in
Socket

dotenv-schema-rails

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-schema-rails

0.0.1
bundlerRubygems
Version published
Maintainers
1
Created
Source

dotenv-schema Build Status

Dotenv-schema makes dotenv schemaful.

Installation

Write .env and .env_schema:

$ cat .env
DB_HOST=db.example.com
DB_PORT=3306

$ cat .env_schema
DB_HOST:
DB_PORT:

Rails

Add this line to your application's Gemfile:

gem 'dotenv-shcmea-rails'
# DO NOT load dotenv-rails gem! Use dotenv-schema-rails instead.

And then execute:

$ bundle
$ rails server

It fails Dotenv::Schema::ValidationError if the validation failed.

Sinatra or Plain ol' Ruby

$ gem install dotenv
require 'dotenv-schema'
Dotenv.load # raises Dotenv::Schema::ValidationError if the validation failed.

Schema validation rule and .env_schema format

.env_schema is based on YAML format.

Basic rule

It fails validation If any variables which are defined in .env_schema don't exist in .env.

# .env_schema
DB_HOST:
DB_PORT:

# .env
DB_HOST=db.example.com
# => Dotenv::Schema::ValidationError: ENV['DB_PORT'] must exist

It fails validation If any variables which aren't defined in .env_schema exist in .env.

# .env_schema
DB_HOST:

# .env
DB_HOST=db.example.com
DB_PORT=3306
# => Dotenv::Schema::ValidationError: Undefined variable(s): DB_PORT; Please add them into .env_schema

To allow empty string

In default, it fails if any environment variables in .env are empty string.

# .env_schema
DB_HOST:

# .env
DB_HOST=
# => Dotenv::Schema::ValidationError: ENV['DB_HOST'] must not be empty string

You can allow it by using allow_empty_string option.

# .env_schema
DB_HOST:
  allow_empty_string: true

# .env
DB_HOST=
# => Passes validation even though DB_HOST is empty

To allow variables to don't exist

# .env_schema
DB_HOST:
DB_PORT:
  allow_not_exists: true

# .env
DB_HOST=
# => Passes validation even though DB_PORT doesn't exist

FAQs

Package last updated on 26 Oct 2013

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.