module

LuckyEnv

Constants

VERSION = {{ (`shards version \"/tmp/tmp.PjcPnK/src/src\"`).chomp.stringify }}

Class methods

development?
Source
environment
Source
load(file_path : String) : Hash(String, String)

Parses the file_path, and loads the results in to ENV raises LuckyEnv::MissingFileError if the file is missing

Source
load

Loads the appropriate environment file from the project root directory based on the value of ENV["LUCKY_ENV"].

This method attempts to read one of the following files depending on the environment:

  • .env.development for the development environment
  • .env.production for the production environment
  • .env.testing for the testing environment

Falls back to reading .env if no specific file is found for the current environment. raises LuckyEnv::MissingFileError if no environment file is found.

Source
load?(file_path : String) : Hash(String, String) | Nil

Returns nil if the file is missing

Source
production?
Source
task?
Source
test?
Source

Macros

add_env(name)
Source
init_env(path = ".env")

Generates type-safe method definitions for env variables.

Usage: LuckyEnv.init_env or LuckyEnv.init_env "/path/to/env-file"

Env File:

LUCKY_ENV    = development
DEV_PORT     = 3500
ENABLE_CACHE = true

Output:

def LuckyEnv.lucky_env : String
  ENV["LUCKY_ENV"]
end

def LuckyEnv.dev_port : Int32
  ENV["DEV_PORT"].to_i
end

def LuckyEnv.enable_cache? : Bool
  ENV["enable_cache"] == "true"
end
Source

Nested types