Module: Merb::Orms::DataMapper
- Defined in:
- lib/merb/orms/data_mapper/connection.rb
Class Method Summary collapse
- .config ⇒ Object
- .config_file ⇒ Object
-
.connect ⇒ Object
Database connects as soon as the gem is loaded.
- .copy_sample_config ⇒ Object
-
.register_session_type ⇒ Object
Registering this ORM lets the user choose DataMapper as a session store in merb.yml’s session_store: option.
- .sample_dest ⇒ Object
- .sample_source ⇒ Object
Class Method Details
.config ⇒ Object
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_file ⇒ Object
8 |
# File 'lib/merb/orms/data_mapper/connection.rb', line 8 def config_file() MERB_ROOT / "config" / "database.yml" end |
.connect ⇒ Object
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_config ⇒ Object
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_type ⇒ Object
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_dest ⇒ Object
9 |
# File 'lib/merb/orms/data_mapper/connection.rb', line 9 def sample_dest() MERB_ROOT / "config" / "database.sample.yml" end |
.sample_source ⇒ Object
10 |
# File 'lib/merb/orms/data_mapper/connection.rb', line 10 def sample_source() File.dirname(__FILE__) / "database.sample.yml" end |