2010-04-09 05:12:28 +02:00
|
|
|
require "pathname"
|
2010-04-09 02:57:10 +02:00
|
|
|
require "active_record"
|
|
|
|
require "active_record/version"
|
|
|
|
|
2010-09-26 23:05:02 +02:00
|
|
|
module ActiveRecord::Import
|
2010-08-11 02:46:32 +02:00
|
|
|
AdapterPath = File.join File.expand_path(File.dirname(__FILE__)), "/active_record/adapters"
|
2010-09-26 23:05:02 +02:00
|
|
|
|
2012-02-25 16:36:43 +01:00
|
|
|
def self.base_adapter(adapter)
|
|
|
|
case adapter
|
|
|
|
when 'mysqlspatial' then 'mysql'
|
2012-12-14 16:29:04 +01:00
|
|
|
when 'mysql2spatial' then 'mysql2'
|
2012-02-25 16:36:43 +01:00
|
|
|
when 'spatialite' then 'sqlite3'
|
|
|
|
when 'postgis' then 'postgresql'
|
|
|
|
else adapter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-26 22:51:19 +02:00
|
|
|
# Loads the import functionality for a specific database adapter
|
2010-04-09 02:57:10 +02:00
|
|
|
def self.require_adapter(adapter)
|
2010-08-11 02:46:32 +02:00
|
|
|
require File.join(AdapterPath,"/abstract_adapter")
|
2012-02-25 16:36:43 +01:00
|
|
|
require File.join(AdapterPath,"/#{base_adapter(adapter)}_adapter")
|
2010-04-09 02:57:10 +02:00
|
|
|
end
|
2010-09-26 22:51:19 +02:00
|
|
|
|
2010-09-27 02:47:27 +02:00
|
|
|
# Loads the import functionality for the passed in ActiveRecord connection
|
2011-10-10 19:07:10 +02:00
|
|
|
def self.load_from_connection_pool(connection_pool)
|
|
|
|
require_adapter connection_pool.spec.config[:adapter]
|
2010-09-26 22:51:19 +02:00
|
|
|
end
|
2010-04-09 02:57:10 +02:00
|
|
|
end
|
|
|
|
|
2010-09-27 02:47:27 +02:00
|
|
|
|
2010-04-09 05:12:28 +02:00
|
|
|
this_dir = Pathname.new File.dirname(__FILE__)
|
2011-06-23 01:01:33 +02:00
|
|
|
require this_dir.join("import").to_s
|
|
|
|
require this_dir.join("active_record/adapters/abstract_adapter").to_s
|
|
|
|
require this_dir.join("synchronize").to_s
|