Module: Hanami::Env

Defined in:
lib/hanami/env.rb

Overview

Since:

  • 0.1.0

Class Method Summary collapse

Class Method Details

.load(env = Hanami.env) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Uses [dotenv](github.com/bkeepers/dotenv) (if available) to populate ‘ENV` from various `.env` files.

For a given ‘HANAMI_ENV` environment, the `.env` files are looked up in the following order:

  • .env.environment.local

  • .env.local (unless the environment is ‘test`)

  • .env.environment

  • .env

If dotenv is unavailable, the method exits and does nothing.

Since:

  • 2.0.1



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/hanami/env.rb', line 23

def self.load(env = Hanami.env)
  return unless Hanami.bundled?("dotenv")
  return if loaded?

  dotenv_files = [
    ".env.#{env}.local",
    (".env.local" unless env == :test),
    ".env.#{env}",
    ".env"
  ].compact

  require "dotenv"
  Dotenv.load(*dotenv_files)

  loaded!
end

.loaded!Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.0.1



48
49
50
# File 'lib/hanami/env.rb', line 48

def self.loaded!
  @_loaded = true
end

.loaded?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)

Since:

  • 2.0.1



42
43
44
# File 'lib/hanami/env.rb', line 42

def self.loaded?
  @_loaded
end