Module: Kamaze::Project::Concern::Env

Included in:
Kamaze::Project
Defined in:
lib/kamaze/project/concern/env.rb

Overview

Load dotenv file

Storing configuration in the environment is one of the tenets of a twelve-factor app. Anything that is likely to change between deployment environments, such as resource handles for databases or credentials for external services should be extracted from the code into environment variables.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/kamaze/project/concern/env.rb', line 28

def included(base)
  base.class_eval <<-"ACCESSORS", __FILE__, __LINE__ + 1
    protected

    attr_writer :env_loaded
  ACCESSORS
end

Instance Method Details

#env_load(options = {}) ⇒ self (protected)

TODO:

load different (or additionnal) files depending on env/mode

Load .env file (and store result)

Returns:

  • (self)


53
54
55
56
57
58
59
60
61
62
# File 'lib/kamaze/project/concern/env.rb', line 53

def env_load(options = {})
  options[:pwd] = ::Pathname.new(options[:pwd] || Dir.pwd).realpath
  options[:file] ||= '.env'

  [options.fetch(:pwd).join(options.fetch(:file))].each do |file|
    env_loaded.merge!(::Dotenv.load(file))
  end

  self
end

#env_loadedHash

Loaded environment

Returns:

  • (Hash)


40
41
42
43
44
# File 'lib/kamaze/project/concern/env.rb', line 40

def env_loaded
  @env_loaded ||= {}

  @env_loaded
end