Permalink
Browse files

ORM plugins (AR, DM, Sequel) now hook into the BootLoader

ActiveRecord, DataMapper and Sequel plugins have been adapted
to insert a BootLoader to establish the connection right
after the BeforeAppLoads step.
  • Loading branch information...
1 parent af58948 commit 85c2de226bd6aa101a94bdeaf2c7906bc2a34c6e @fabien fabien committed Mar 10, 2008
@@ -1,8 +1,7 @@
namespace :db do
task :merb_start do
- Merb.start :adapter => 'runner',
- :environment => ENV['MERB_ENV'] || 'development'
+ Merb.start :adapter => 'runner', :environment => ENV['MERB_ENV'] || 'development'
end
namespace :create do
@@ -5,8 +5,8 @@ module Merb
module Orms
module ActiveRecord
class << self
- def config_file() Merb.root / "config" / "database.yml" end
- def sample_dest() Merb.root / "config" / "database.yml.sample" end
+ def config_file() Merb.dir_for(:config) / "database.yml" end
+ def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
def copy_sample_config
@@ -1,12 +1,17 @@
-# make sure we're running inside Merb
-if defined?(Merb::Plugins)
+if defined?(Merb::Plugins)
dependency "activerecord"
require File.join(File.dirname(__FILE__) / "merb" / "orms" / "active_record" / "connection")
+ Merb::Plugins.add_rakefiles(File.join(File.dirname(__FILE__) / "active_record" / "merbtasks"))
- Merb::BootLoader.after_app_loads do
- Merb::Orms::ActiveRecord.connect
- Merb::Orms::ActiveRecord.register_session_type
+ class Merb::Orms::ActiveRecord::Connect < Merb::BootLoader
+
+ after BeforeAppRuns
+
+ def self.run
+ Merb::Orms::ActiveRecord.connect
+ Merb::Orms::ActiveRecord.register_session_type
+ end
+
end
-
- Merb::Plugins.add_rakefiles(File.join(File.dirname(__FILE__) / "active_record" / "merbtasks"))
-end
+
+end
@@ -1,5 +1,16 @@
if defined?(Merb::Plugins)
- autoload :DataMapper, File.join(File.dirname(__FILE__) / "merb_datamapper" / "autoconnect")
-
+ require File.join(File.dirname(__FILE__) / "merb" / "orms" / "data_mapper" / "connection")
+ require File.join(File.dirname(__FILE__) / "merb" / "orms" / "data_mapper" / "base")
Merb::Plugins.add_rakefiles "merb_datamapper" / "merbtasks"
+
+ class Merb::Orms::DataMapper::Connect < Merb::BootLoader
+
+ after BeforeAppRuns
+
+ def self.run
+ Merb::Orms::DataMapper.connect
+ Merb::Orms::DataMapper.register_session_type
+ end
+
+ end
end
@@ -1,5 +0,0 @@
-require File.join(File.dirname(__FILE__) / ".." / "merb" / "orms" / "data_mapper" / "connection")
-require File.join(File.dirname(__FILE__) / ".." / "merb" / "orms" / "data_mapper" / "base")
-
-Merb::Orms::DataMapper.connect
-Merb::Orms::DataMapper.register_session_type
@@ -1,11 +1,17 @@
if defined?(Merb::Plugins)
Merb::Plugins.config[:merb_sequel] = {}
require File.join(File.dirname(__FILE__) / "merb" / "orms" / "sequel" / "connection")
+ Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
- Merb::BootLoader.after_app_loads do
- Merb::Orms::Sequel.connect
- Merb::Orms::Sequel.register_session_type
+ class Merb::Orms::Sequel::Connect < Merb::BootLoader
+
+ after BeforeAppRuns
+
+ def self.run
+ Merb::Orms::Sequel.connect
+ Merb::Orms::Sequel.register_session_type
+ end
+
end
- Merb::Plugins.add_rakefiles "merb_sequel" / "merbtasks"
end

0 comments on commit 85c2de2

Please sign in to comment.