Sha256: 8a5386b7f6187738a6e1124e5613327d503d8f81f86fdaea282c5817902ef02f

Contents?: true

Size: 836 Bytes

Versions: 2

Compression:

Stored size: 836 Bytes

Contents

class Baza::Cloner
  def self.from_active_record_connection(connection)
    if connection.class.name.include?('Mysql2Adapter')
      connection = connection.instance_variable_get(:@connection)

      config = connection.instance_variable_get(:@query_options)
      config ||= connection.instance_variable_get(:@config)

      db_args = {
        type: :mysql2,
        host: config[:host],
        user: config[:username],
        pass: config[:password],
        db: config[:database]
      }

      Baza::Db.new(db_args)
    elsif connection.class.name.include?('MysqlAdapter')
      connection = connection.instance_variable_get(:@connection)

      db_args = {
        type: :mysql,
        conn: connection
      }

      Baza::Db.new(db_args)
    else
      raise "Unsupported adapter: #{connection.class.name}"
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
baza-0.0.19 lib/baza/cloner.rb
baza-0.0.18 lib/baza/cloner.rb