Module: ActiveUUID::Patches::ConnectionHandling

Defined in:
lib/activeuuid/patches.rb

Instance Method Summary collapse

Instance Method Details

#establish_connection(_ = nil) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# File 'lib/activeuuid/patches.rb', line 192

def establish_connection(_ = nil)
  super

  aca = ActiveRecord::ConnectionAdapters

  aca::Table.send           :include, Migrations if defined? aca::Table
  aca::TableDefinition.send :include, Migrations if defined? aca::TableDefinition

  if ActiveRecord::VERSION::MAJOR >= 5
    if defined? aca::AbstractMysqlAdapter
      aca::AbstractMysqlAdapter.prepend TypeMapOverride
      aca::AbstractMysqlAdapter.prepend MysqlTypeToSqlOverride
    end

    aca::SQLite3Adapter.prepend        TypeMapOverride        if defined? aca::SQLite3Adapter
    aca::PostgreSQL::OID::Uuid.prepend PostgresqlTypeOverride if defined? aca::PostgreSQLAdapter

  elsif ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 2
    aca::Mysql2Adapter.prepend  TypeMapOverride if defined? aca::Mysql2Adapter
    aca::SQLite3Adapter.prepend TypeMapOverride if defined? aca::SQLite3Adapter

  else
    aca::Column.send           :prepend, Column
    aca::PostgreSQLColumn.send :prepend, PostgreSQLColumn if defined? aca::PostgreSQLColumn
  end

  aca::MysqlAdapter.send      :prepend, Quoting           if defined? aca::MysqlAdapter
  aca::Mysql2Adapter.send     :prepend, Quoting           if defined? aca::Mysql2Adapter
  aca::SQLite3Adapter.send    :prepend, Quoting           if defined? aca::SQLite3Adapter
  aca::PostgreSQLAdapter.send :prepend, PostgreSQLQuoting if defined? aca::PostgreSQLAdapter
end