Skip to content

Instantly share code, notes, and snippets.

@bcardiff
Created November 10, 2017 03:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcardiff/129962b01266dccfa2fc5ee8ba2ea042 to your computer and use it in GitHub Desktop.
Save bcardiff/129962b01266dccfa2fc5ee8ba2ea042 to your computer and use it in GitHub Desktop.
crystal-env preview

crystal-env

This shard provides environment detection. The selected environment is configured using CRYSTAL_ENV environment variable.

Installation

Add this to your application's shard.yml:

dependencies:
  env:
    github: crystal-lang/crystal-env

Usage

  • Add the following require in the application code. The default environment will be development.
require "env"
  • In the spec/spec_helper.cr require env/spec before your app code. When running crystal spec the default environment will be test.
require "spec"
require "env/spec"
require "../your-app"
  • Use the following methods to detect the environment

    • Crystal.env.development?
    • Crystal.env.production?
    • Crystal.env.test?
  • Set CRYSTAL_ENV to development, production or test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment