Class: Sequelizer::EnvConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/sequelizer/env_config.rb

Overview

Creates a set of database configuration options from environment variables

Instance Method Summary collapse

Instance Method Details

#optionsObject

Any environment variables in the .env file are loaded and then any environment variable starting with SEQUELIZER_ will be used as an option for the database



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/sequelizer/env_config.rb', line 11

def options
  Dotenv.load

  seq_config = ENV.keys.grep(/^SEQUELIZER_/).each_with_object({}) do |key, config|
    new_key = key.gsub(/^SEQUELIZER_/, '').downcase
    config[new_key] = ENV.fetch(key, nil)
  end

  db_config = ENV.keys.grep(/_DB_OPT_/).each_with_object({}) do |key, config|
    new_key = key.downcase
    config[new_key] = ENV.fetch(key, nil)
  end

  db_config.merge(seq_config)
end