Load database gems based on config/database.yml settings.

This commit is contained in:
Martin Edenhofer 2016-01-22 11:56:32 +01:00
parent b4dd569cda
commit 81971899a0
2 changed files with 33 additions and 5 deletions

36
Gemfile
View file

@ -52,9 +52,33 @@ gem 'libv8'
gem 'execjs'
gem 'therubyracer'
# e. g. for mysql you need to load mysql
gem 'mysql2', '~> 0.3.20'
gem 'pg'
# Include database gems for the adapters found in the database
# configuration file, thanks to redmine, taken from https://github.com/redmine/redmine/blob/master/Gemfile
require 'erb'
require 'yaml'
database_file = File.join(File.dirname(__FILE__), 'config/database.yml')
if File.exist?(database_file)
database_config = YAML.load(ERB.new(IO.read(database_file)).result)
adapters = database_config.values.map { |c| c['adapter'] }.compact.uniq
if adapters.any?
adapters.each do |adapter|
case adapter
when 'mysql2'
gem 'mysql2', '~> 0.3.20'
when /postgresql/
gem 'pg'
when /sqlite3/
gem 'sqlite3'
else
warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
end
end
else
warn('No adapter found in config/database.yml, please configure it first')
end
else
warn('Please configure your config/database.yml first')
end
gem 'net-ldap'
@ -97,3 +121,9 @@ group :development, :test do
end
gem 'puma'
# load onw gem's
local_gemfile = File.join(File.dirname(__FILE__), 'Gemfile.local')
if File.exist?(local_gemfile)
eval_gemfile local_gemfile
end

View file

@ -154,7 +154,6 @@ GEM
multi_json (1.11.2)
multi_xml (0.5.5)
multipart-post (2.0.0)
mysql2 (0.3.20)
naught (1.1.0)
nenv (0.2.0)
net-ldap (0.13.0)
@ -349,7 +348,6 @@ DEPENDENCIES
libv8
mail (~> 2.5.0)
mime-types
mysql2 (~> 0.3.20)
net-ldap
omniauth
omniauth-facebook