Module: WithAdvisoryLock::JRubyAdapter

Defined in:
lib/with_advisory_lock/jruby_adapter.rb

Class Method Summary collapse

Class Method Details

.install!Object

JRuby compatibility - ensure adapters are patched after they’re loaded



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/with_advisory_lock/jruby_adapter.rb', line 6

def self.install!
  ActiveSupport.on_load :active_record do
    ActiveRecord::Base.singleton_class.prepend(Module.new do
      def connection
        super.tap do |conn|
          case conn
          when ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
            unless conn.class.include?(WithAdvisoryLock::CoreAdvisory)
              conn.class.prepend WithAdvisoryLock::CoreAdvisory
              conn.class.prepend WithAdvisoryLock::PostgreSQLAdvisory
            end
          when ActiveRecord::ConnectionAdapters::Mysql2Adapter, ActiveRecord::ConnectionAdapters::TrilogyAdapter
            unless conn.class.include?(WithAdvisoryLock::CoreAdvisory)
              conn.class.prepend WithAdvisoryLock::CoreAdvisory
              conn.class.prepend WithAdvisoryLock::MySQLAdvisory
            end
          end
        end
      end
    end)
  end
end