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
-
#env_load(**options) ⇒ self
protected
Load
.env
file (and store result). -
#env_loaded ⇒ Hash
Loaded environment.
Class Method Details
.included(base) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/kamaze/project/concern/env.rb', line 29 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)
Load .env
file (and store result)
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/kamaze/project/concern/env.rb', line 50 def env_load(**) = { # @formatter:off pwd: Pathname.new([:pwd] || Dir.pwd).realpath, file: '.env', # @formatter:on }.merge() # @todo load different (or additionnal) files depending on env/mode [Pathname.new(.fetch(:pwd)).join(.fetch(:file))].each do |file| env_loaded.merge!(Dotenv.load(file)) end self end |
#env_loaded ⇒ Hash
Loaded environment
41 42 43 |
# File 'lib/kamaze/project/concern/env.rb', line 41 def env_loaded @env_loaded ||= {} end |