Module: TpCommon::AppConfig::Environment

Defined in:
lib/tp_common/app_config/environment.rb

Class Method Summary collapse

Class Method Details

.clear!Object

Clear @app_config, use for testing only



43
44
45
# File 'lib/tp_common/app_config/environment.rb', line 43

def clear!
  @app_config = nil
end

.fetch(key) ⇒ Object

2 levels of configuration:

config/app_config.yml “‘

app:
  name:
    detail:
db:
  readonly: true

“‘

Environment variables. Variable name will be downcase and replace ‘__` by `.` “`

APP__NAME__DETAIL=octopus
APP__NAME2=octopus2

“‘ Value in environment variable will overwrite value in `config/app_config.yml` BUT key will be ignore if doesn’t exists in ‘config/app_config.yml` So in case above, “`

TpCommon::AppConfig::Environment.fetch(:'app.name.detail') # => "octopus"
TpCommon::AppConfig::Environment.fetch(:'app.name2') # => nil

“‘ We could mixed both to use, but we recommend:

use `config/app_config.yml` which committed to repo to know
  how many, what are config we use in app
  with default value (optional)
use environment variables for differences config between stages (producion, staging, pre-production, ...)


37
38
39
40
# File 'lib/tp_common/app_config/environment.rb', line 37

def fetch(key)
  @app_config ||= load_config
  @app_config[key]
end