You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: pg_instance.rb
    path of file: ./repos/pgcat/tests/ruby/helpers
    
    the code of the file until where you have to start completion: require 'pg'
require 'toxiproxy'

class PgInstance
  attr_reader :port
  attr_reader :username
  attr_reader :password
  attr_reader :database_name

  def self.mass_takedown(databases)
    raise StandardError "block missing" unless block_given?

    databases.each do |database|
      database.toxiproxy.toxic(:limit_data, bytes: 1).toxics.each(&:save)
    end
    sleep 0.1
    yield
  ensure
    databases.each do |database|
      database.toxiproxy.toxics.each(&:destroy)
    end
  end

  def initialize(port, username, password, database_name)
    @original_port = port.to_i
    @toxiproxy_port = 10000 + port.to_i
    @port = @toxiproxy_port.to_i

    @username = username
    @password = password
    @database_name = database_name
    @toxiproxy_name = "database_#{@original_port}"
    Toxiproxy.populate([{
      name: @toxiproxy_name,
      listen: "0.0.0.0:#{@toxiproxy_port}",
      upstream: "localhost:#{@original_port}",
    }])

    # Toxiproxy server 
    
  def initialize(port, username, password, database_name)
    @original_port = port.to_i
    @toxiproxy_port = 10000 + port.to_i
    @port = @toxiproxy_port.to_i

    @username = username
    @password = password
    @database_name = database_name
    @toxiproxy_name = "database_#{@original_port}"
    Toxiproxy.populate([{
      name: @toxiproxy_name,
      listen: "0.0.0.0:#{@toxiproxy_port}",
      upstream: "localhost:#{@original_port}",
    }])

    # Toxiproxy server will outlive our PgInstance objects
    # so we want to destroy our proxies before exiting
    # Ruby finalizer is ideal for doing this
    ObjectSpace.define_finalizer(@toxiproxy_name, proc { Toxiproxy[@toxiproxy_name].destroy })
  end

  def with_connection
    conn = PG.connect("postgres://#{@username}:#{@password}@localhost:#{port}/#{database_name}")
    yield conn
  ensure
    conn&.close
  end

  def reset
    reset_toxics
    reset_stats
    drop_connections
    sleep 0.1
  end

  def toxiproxy
    Toxiproxy[@toxiproxy_name]
  end

  def take_down
    if block_given?
      Toxiproxy[@toxiproxy_name].toxic(:limit_data, bytes: 1).apply { yield }
    else
      Toxiproxy[@toxiproxy_name].toxic(:limit_data, bytes: 1).toxics.each(&:save)
    end
  end