Module: EnvJson

Defined in:
lib/env_json.rb,
lib/env_json/railtie.rb,
lib/env_json/version.rb

Overview

Module containing utilities for loading a JSON file into environments variables. see #load_env_from_source_with_overrides

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

VERSION =

EnvJson version

"0.3.2"

Class Method Summary collapse

Class Method Details

.envHash

return the consolidated env built by #load_env_from_source_with_overrides

Returns:

  • (Hash)

    the environment variables loaded from JSON



22
23
24
# File 'lib/env_json.rb', line 22

def env
  @env or fail 'call load_env_from_source_with_overrides first'
end

.load_env_from_source_with_overrides(json, environment_name = nil) ⇒ Hash

Load environments variables from a source into ENV

Parameters:

  • json (#read)

    any source that can be read by JSON.load

  • environment_name (#to_str, nil) (defaults to: nil)

    the environment name from where to take overrides

Returns:

  • (Hash)

    the loaded environment variables



13
14
15
16
17
18
# File 'lib/env_json.rb', line 13

def load_env_from_source_with_overrides(json, environment_name=nil)
  json = JSON.load(json)
  @env = generate_configuration(json, environment_name).tap do |configuration|
    apply_env(configuration)
  end
end