Module: Merb::Orms::DataMapper

Defined in:
lib/merb/orms/data_mapper/connection.rb

Class Method Summary collapse

Class Method Details

.configObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/merb/orms/data_mapper/connection.rb', line 16

def config
  @config ||=
    begin
      # Convert string keys to symbols
      full_config = Erubis.load_yaml_file(config_file)
      config = (Merb::Plugins.config[:merb_data_mapper] = {})
      (full_config[MERB_ENV.to_sym] || full_config[MERB_ENV]).each { |k, v| config[k.to_sym] = v }
      config
    end
end

.config_fileObject



8
# File 'lib/merb/orms/data_mapper/connection.rb', line 8

def config_file() MERB_ROOT / "config" / "database.yml" end

.connectObject

Database connects as soon as the gem is loaded



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/merb/orms/data_mapper/connection.rb', line 28

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

.copy_sample_configObject



12
13
14
# File 'lib/merb/orms/data_mapper/connection.rb', line 12

def copy_sample_config
  FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
end

.register_session_typeObject

Registering this ORM lets the user choose DataMapper as a session store in merb.yml’s session_store: option.



42
43
44
45
46
# File 'lib/merb/orms/data_mapper/connection.rb', line 42

def register_session_type
  Merb::Server.register_session_type("data_mapper",
    "merb/session/data_mapper_session",
    "Using DataMapper database sessions")
end

.sample_destObject



9
# File 'lib/merb/orms/data_mapper/connection.rb', line 9

def sample_dest() MERB_ROOT / "config" / "database.sample.yml" end

.sample_sourceObject



10
# File 'lib/merb/orms/data_mapper/connection.rb', line 10

def sample_source() File.dirname(__FILE__) / "database.sample.yml" end