class Poncho::Parser

Overview

Poncho::Parser is a .env file parser

Poncho parses the contents of your file containing environment variables is available to use. It accepts a String or IO and will return an Hash with the parsed keys and values.

Rules

Poncho parser currently supports the following rules:

Overrides

By default, Poncho won't overwrite existing environment variables as dotenv assumes the deployment environment has more knowledge about configuration than the application does. To overwrite existing environment variables you can use Poncho.parse!(string_or_io) / Poncho.from_file(file, overwrite: true) and Poncho.parse(string_or_io, overwrite: true).

Parse file

parser = Poncho::Parser.from_file(".env")
parser["ENV"] # => "development"

Parse raw string

parser = Poncho::Parser.new("ENV=development\nDB_NAME=poncho\nENV=production")
parser.parse
parser["ENV"] # => "development"

# Overwrite the key
parser.parse!
parser["ENV"] # => "production"

Defined in:

poncho/parser.cr

Constructors

Class Method Summary

Instance Method Summary

Macro Summary

Constructor Detail

def self.new(raw : String | IO) #

[View source]

Class Method Detail

def self.from_file(file : String, overwrite = false) #

[View source]

Instance Method Detail

def parse(overwrite = false) #

Parse environment variables


[View source]
def parse! #

Parse environment variables and overwrite existing ones.

Same as #parse(overwrite: true)


[View source]
def to_h : Hash(String, String) #

Returns this collection as a plain Hash.


[View source]

Macro Detail

macro method_missing(call) #

[View source]