Skip to content

Instantly share code, notes, and snippets.

@jpawlyn
Last active May 24, 2021 04:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpawlyn/dbb2b3c27adf2c5b31edda0c00133ced to your computer and use it in GitHub Desktop.
Save jpawlyn/dbb2b3c27adf2c5b31edda0c00133ced to your computer and use it in GitHub Desktop.
module MyGem
class DbConfig
CONFIGURATIONS = Psych.safe_load(
ERB.new(
File.read(File.join(File.dirname(__FILE__), '../../config/databases.yml'))
).result,
aliases: true
)
DB_ENV = (Rails.env if defined?(Rails)) || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
class << self
def configurations
CONFIGURATIONS[DB_ENV.to_s]
end
def db_key
RequestStore.store[:mygem_database_key]
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment