Module: Merb::Orms::ActiveRecord
- Defined in:
- lib/merb/orms/active_record/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 active_record as a session 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 26 |
# File 'lib/merb/orms/active_record/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_active_record] = {}) (full_config[MERB_ENV.to_sym] || full_config[MERB_ENV]).each { |k, v| config[k.to_sym] = v } ::ActiveRecord::Base.configurations= full_config config end end |
.config_file ⇒ Object
8 |
# File 'lib/merb/orms/active_record/connection.rb', line 8 def config_file() MERB_ROOT / "config" / "database.yml" end |
.connect ⇒ Object
Database connects as soon as the gem is loaded
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/merb/orms/active_record/connection.rb', line 29 def connect if File.exists?(config_file) puts "Connecting to database..." Thread.new{ loop{ sleep(60*60); ::ActiveRecord::Base.verify_active_connections! } }.priority = -10 ::ActiveRecord::Base.verification_timeout = 14400 ::ActiveRecord::Base.logger = MERB_LOGGER ::ActiveRecord::Base.establish_connection 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/active_record/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 active_record as a session in merb.yml’s session_store: option.
48 49 50 51 52 |
# File 'lib/merb/orms/active_record/connection.rb', line 48 def register_session_type Merb::Server.register_session_type("active_record", "merb/session/active_record_session", "Using ActiveRecord database sessions") end |
.sample_dest ⇒ Object
9 |
# File 'lib/merb/orms/active_record/connection.rb', line 9 def sample_dest() MERB_ROOT / "config" / "database.sample.yml" end |
.sample_source ⇒ Object
10 |
# File 'lib/merb/orms/active_record/connection.rb', line 10 def sample_source() File.dirname(__FILE__) / "database.sample.yml" end |