Sha256: 324c0403c3fe23a0d1acfa5ece1f13b2412d1b64418229e40560bccbc8b50373

Contents?: true

Size: 1.01 KB

Versions: 1

Compression:

Stored size: 1.01 KB

Contents

module ActiveRecord
  module Dowsing
    class Railtie < ::Rails::Railtie
      initializer 'ActiveRecord::Dowsing patch' do
        next unless Rails.configuration.x.activerecord_dowsing.enabled

        ActiveSupport.on_load :active_record do
          configuration = ActiveRecord::Base.connection_config
          resolver = ActiveRecord::ConnectionAdapters::ConnectionSpecification::Resolver.new({})
          adapter_method = resolver.spec(configuration).adapter_method
          adapter = ActiveRecord::Base.public_send(adapter_method, configuration)

          if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) && adapter.is_a?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
            PG::Connection.prepend(ActiveRecord::Dowsing::PgConnectionPatch)
          elsif defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && adapter.is_a?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
            adapter.class.prepend(ActiveRecord::Dowsing::Patch)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord-dowsing-1.0.0 lib/active_record/dowsing/railtie.rb