Class: Ocelot::Connection
- Inherits:
-
Object
- Object
- Ocelot::Connection
- Defined in:
- lib/ocelot/database.rb
Instance Attribute Summary collapse
-
#source ⇒ Object
Returns the value of attribute source.
-
#target ⇒ Object
Returns the value of attribute target.
-
#use_source ⇒ Object
Returns the value of attribute use_source.
Instance Method Summary collapse
- #current_connection ⇒ Object
-
#initialize(source, target) ⇒ Connection
constructor
A new instance of Connection.
Constructor Details
#initialize(source, target) ⇒ Connection
Returns a new instance of Connection.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ocelot/database.rb', line 11 def initialize(source, target) [source, target].each do |db| require "active_record/connection_adapters/#{db['adapter']}_adapter" end self.target = ActiveRecord::Base.send("#{target['adapter']}_connection".to_s, target.symbolize_keys!) self.source = ActiveRecord::Base.send("#{source['adapter']}_connection".to_s, source.symbolize_keys!) self.use_source = true # AR doesn't like oop much, monkeypatch lots o stuff, 1.8.7 compatability ocelot_conn = self ActiveRecord::ConnectionAdapters::ConnectionHandler.class_eval do @@conn = ocelot_conn def retrieve_connection(klass) @@conn.current_connection end end ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do attr_reader :last_query def log_with_last_query(sql, name, &block) @last_query = [sql, name] log_without_last_query(sql, name, &block) end alias_method_chain :log, :last_query end end |
Instance Attribute Details
#source ⇒ Object
Returns the value of attribute source.
7 8 9 |
# File 'lib/ocelot/database.rb', line 7 def source @source end |
#target ⇒ Object
Returns the value of attribute target.
8 9 10 |
# File 'lib/ocelot/database.rb', line 8 def target @target end |
#use_source ⇒ Object
Returns the value of attribute use_source.
9 10 11 |
# File 'lib/ocelot/database.rb', line 9 def use_source @use_source end |
Instance Method Details
#current_connection ⇒ Object
44 45 46 |
# File 'lib/ocelot/database.rb', line 44 def current_connection self.use_source ? source : target end |