Sha256: e468b2821da20ce576f6c1820095deb7b398a94e89815b57d4a5519633beb894
Contents?: true
Size: 1.69 KB
Versions: 1
Compression:
Stored size: 1.69 KB
Contents
require 'fileutils' require 'data_mapper' module Merb module Orms module DataMapper class << self def config_file() Merb.root / "config" / "database.yml" end def sample_dest() Merb.root / "config" / "database.sample.yml" end def sample_source() File.dirname(__FILE__) / "database.sample.yml" end def copy_sample_config FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest) end def config @config ||= begin # Convert string keys to symbols full_config = Erubis.load_yaml_file(config_file) config = (Merb::Plugins.config[:merb_datamapper] = {}) (full_config[Merb.environment.to_sym] || full_config[Merb.environment]).each { |k, v| config[k.to_sym] = v } config end end # Database connects as soon as the gem is loaded def connect if File.exists?(config_file) puts "Connecting to database..." ::DataMapper::Database.setup(config) else copy_sample_config puts "No database.yml file found in #{Merb.root}/config." puts "A sample file was created called database.sample.yml for you to copy and edit." exit(1) end end # Registering this ORM lets the user choose DataMapper as a session store # in merb.yml's session_store: option. def register_session_type Merb::BootLoader.register_session_type("datamapper", "merb/session/data_mapper_session", "Using DataMapper database sessions") end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
merb_datamapper-0.5 | lib/merb/orms/data_mapper/connection.rb |