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

32
Gemfile
View file

@ -52,9 +52,33 @@ gem 'libv8'
gem 'execjs' gem 'execjs'
gem 'therubyracer' gem 'therubyracer'
# e. g. for mysql you need to load mysql # 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' gem 'mysql2', '~> 0.3.20'
when /postgresql/
gem 'pg' 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' gem 'net-ldap'
@ -97,3 +121,9 @@ group :development, :test do
end end
gem 'puma' 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_json (1.11.2)
multi_xml (0.5.5) multi_xml (0.5.5)
multipart-post (2.0.0) multipart-post (2.0.0)
mysql2 (0.3.20)
naught (1.1.0) naught (1.1.0)
nenv (0.2.0) nenv (0.2.0)
net-ldap (0.13.0) net-ldap (0.13.0)
@ -349,7 +348,6 @@ DEPENDENCIES
libv8 libv8
mail (~> 2.5.0) mail (~> 2.5.0)
mime-types mime-types
mysql2 (~> 0.3.20)
net-ldap net-ldap
omniauth omniauth
omniauth-facebook omniauth-facebook