Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

acts_as_fu can use different database config independent from your ap…

…plication's database config
  • Loading branch information...
commit 3248163d298cc2f89a0da2c6899f568caf1bb7ed 1 parent 4563a96
Joe Moore & Ryan Dy authored
Showing with 17 additions and 12 deletions.
  1. +17 −12 lib/acts_as_fu/base.rb
View
29 lib/acts_as_fu/base.rb
@@ -4,14 +4,18 @@
RAILS_ENV = 'test' unless defined?(RAILS_ENV)
module ActsAsFu
- class << self
- attr_reader :log
-
- def connect!(config={})
+
+ class Connection < ActiveRecord::Base
+ cattr_accessor :acts_as_fu_connected
+ cattr_reader :log
+ self.abstract_class = true
+
+ def self.connect!(config={})
+# p "ActsAsFu::Connection for #{config.inspect}"
@log = ""
- ActiveRecord::Base.logger = Logger.new(StringIO.new(log))
- ActiveRecord::Base.connection.disconnect! rescue nil
- ActiveRecord::Base.establish_connection(config)
+# self.logger = Logger.new(StringIO.new(log))
+# self.connection.disconnect! rescue nil
+ self.establish_connection(config)
end
end
@@ -19,8 +23,8 @@ def build_model(name, options={}, &block)
connect! unless connected?
super_class = options[:superclass] || begin
- ActiveRecord::Base.connection.create_table(name, :force => true) { }
- ActiveRecord::Base
+ ActsAsFu::Connection.connection.create_table(name, :force => true) { }
+ ActsAsFu::Connection
end
set_class!(name, super_class, &block)
@@ -40,20 +44,21 @@ def set_class!(name, super_class, &block)
end
def connect!
- ActsAsFu.connect!({
+ ActsAsFu::Connection.connect!({
:adapter => "sqlite3",
:database => ":memory:"
})
+ ActsAsFu::Connection.acts_as_fu_connected = true
end
def connected?
- ActiveRecord::Base.connected?
+ ActsAsFu::Connection.acts_as_fu_connected
end
def model_eval(klass, &block)
class << klass
def method_missing_with_columns(sym, *args, &block)
- ActiveRecord::Base.connection.change_table(name.tableize) do |t|
+ ActsAsFu::Connection.connection.change_table(name.tableize) do |t|
t.send(sym, *args)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.