Sha256: 3eb2707e56fe68f831de1c0c0d50e94e4bc866f46ce7dfd67af866f599fb5841

Contents?: true

Size: 929 Bytes

Versions: 15

Compression:

Stored size: 929 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)
      connection = connection.instance_variable_get(:@connection) if RUBY_PLATFORM == "java"

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

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
baza-0.0.35 lib/baza/cloner.rb
baza-0.0.34 lib/baza/cloner.rb
baza-0.0.33 lib/baza/cloner.rb
baza-0.0.32 lib/baza/cloner.rb
baza-0.0.31 lib/baza/cloner.rb
baza-0.0.30 lib/baza/cloner.rb
baza-0.0.29 lib/baza/cloner.rb
baza-0.0.28 lib/baza/cloner.rb
baza-0.0.27 lib/baza/cloner.rb
baza-0.0.26 lib/baza/cloner.rb
baza-0.0.25 lib/baza/cloner.rb
baza-0.0.24 lib/baza/cloner.rb
baza-0.0.23 lib/baza/cloner.rb
baza-0.0.22 lib/baza/cloner.rb
baza-0.0.21 lib/baza/cloner.rb