Class: Lucid::Utils::ConfigFromFile

Inherits:
Object
  • Object
show all
Defined in:
lib/lucid/utils/config_from_file.rb

Instance Method Summary collapse

Instance Method Details

#call(path, env_prefix: nil) ⇒ Hash

Parameters:

  • path (String)
  • env_prefix (String, nil) (defaults to: nil)

    environment variables override values in the file

Returns:

  • (Hash)


10
11
12
13
14
15
16
# File 'lib/lucid/utils/config_from_file.rb', line 10

def call(path, env_prefix: nil)
  instance_eval(File.read(path)).tap do |result|
    raise TypeError, 'not and instance of Hash' unless result.is_a?(Hash)
  end.then do |config|
    env_prefix ? env_overrides(config, env_prefix) : config
  end
end