module Rails::DataMapper
Public Class Methods
create_connection()
click to toggle source
# File lib/datamapper4rails/rails_datamapper.rb, line 9 def create_connection # TODO: handle Rails and Merb style database.yml files conf = config.dup repositories = conf.delete(:repositories) if(repositories) repositories.each do |key, config| ::DataMapper.setup(key.to_sym, config) end else ::DataMapper.setup(:default, conf) unless conf.empty? end end
Private Class Methods
config()
click to toggle source
# File lib/datamapper4rails/rails_datamapper.rb, line 34 def config if hash = full_config[Rails.env] || full_config[Rails.env.to_sym] normalize_config(hash) else raise ArgumentError, "missing environment '#{Rails.env}' in config file #{config_file}" end end
config_file()
click to toggle source
# File lib/datamapper4rails/rails_datamapper.rb, line 24 def config_file Rails.root / 'config' / 'database.yml' end
full_config()
click to toggle source
# File lib/datamapper4rails/rails_datamapper.rb, line 28 def full_config YAML::load(ERB.new(config_file.read).result) end
normalize_config(hash)
click to toggle source
# File lib/datamapper4rails/rails_datamapper.rb, line 44 def normalize_config(hash) config = {} hash.symbolize_keys.each do |key, value| config[key] = if value.kind_of?(Hash) normalize_config(value) elsif key == :port value.to_i elsif key == :adapter && value == 'postgresql' 'postgres' else value end end config end