Sha256: 327a4475ac7687174dab3158b7faf34fd715e617e3110857aab396568d54a030

Contents?: true

Size: 927 Bytes

Versions: 5

Compression:

Stored size: 927 Bytes

Contents

module PgBouncerHero
  class Database

    include Methods::Basics

    attr_reader :id, :config, :group

    def initialize(group, id, config)
      @id = id
      @config = config || {}
      @url = URI.parse(config["url"])
      @group = group
    end

    def name
      @name ||= id.to_s
    end

    def connection
      @connection ||= connection_model.new(host, port, user, password, dbname).connection
    end

    def host
      @url.host if @url
    end

    def port
      @url.port if @url
    end

    def user
      @url.user if @url
    end

    def password
      @url.password if @url
    end

    def dbname
      @url.path[1..-1] if @url
    end

    private

    def connection_model
      @connection_model ||= begin
        Class.new(PgBouncerHero::Connection) do
          def self.name
            "PgBouncerHero::Connection::Database#{object_id}"
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
pgbouncerhero-2.0.0 lib/pgbouncerhero/database.rb
pgbouncerhero-1.0.3 lib/pgbouncerhero/database.rb
pgbouncerhero-1.0.1 lib/pgbouncerhero/database.rb
pgbouncerhero-1.0.0 lib/pgbouncerhero/database.rb
pgbouncerhero-0.1.1 lib/pgbouncerhero/database.rb