Giter Club home page Giter Club logo

dotenv_validator's Introduction

Dotenv Validator

This gem validates .env variables. You can configure validation rules by adding the appropriate comments to the .env.sample file.

Installation

Add the gem to your gemfile:

gem "dotenv_validator", github: "fastruby/dotenv_validator", branch: :main

Call DotenvValidator.check! in an initializer:

echo "DotenvValidator.check!" > "config/initializers/1_dotenv_validator.rb"

Note the 1_ in the name so it's executed before any other initializer, since initializers are run in alphabetical order.

You can use DotenvValidator.check without the ! to show warnings instead of raising an exception.

Updating

At the moment it is only available on Github, so you would need to run:

bundle update --source dotenv_validator

Configuring env variable

In your .env.sample file, you can add comments to tell DotenvValidator how to validate the variable:

MY_REQUIRED_VAR=value #required
THIS_IS_AN_OPTIONAL_INT=123 #format=int
THIS_IS_A_REQUIRED_EMAIL=123 #required,format=email

Formats

  • int or integer
  • float (note that all integers are floats too)
  • str or string (accepts anything)
  • email (checks value against /[\w@]+@[\w@]+\.[\w@]+/)
  • url (checks value against /https?:\/\/.+/)
  • any other value acts as a regexp!

Regexp format

If you have a complex format, you can use a regexp for validation:

MY_WEIRD_ENV_VAR=123_ABC #required,format=\d{3}_\w{3}

In the above example, \d{3}_\w{3} is converted to a regexp and the value is checked against it.

Contributing

Want to make your first contribution to this project? Get started with some of our good first issues!

Bug reports and pull requests are welcome on GitHub at https://github.com/fastruby/dotenv_validator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

When Submitting a Pull Request:

  • If your PR closes any open GitHub issues, please include Closes #XXXX in your comment

  • Please include a summary of the change and which issue is fixed or which feature is introduced.

  • If changes to the behavior are made, clearly describe what changes.

  • If changes to the UI are made, please include screenshots of the before and after.

Sponsorship

FastRuby.io | Rails Upgrade Services

dotenv_validator is maintained and funded by FastRuby.io. The names and logos for FastRuby.io are trademarks of The Lean Software Boutique LLC.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.