Class: PgBouncerHero::Database

Inherits:
Object
  • Object
show all
Includes:
Methods::Basics
Defined in:
lib/pgbouncerhero/database.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Methods::Basics

#clients, #conf, #databases, #lists, #pools, #reload, #shutdown, #stats, #summary, #suspend

Constructor Details

#initialize(group, id, config) ⇒ Database

Returns a new instance of Database.



8
9
10
11
12
13
# File 'lib/pgbouncerhero/database.rb', line 8

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

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



6
7
8
# File 'lib/pgbouncerhero/database.rb', line 6

def config
  @config
end

#groupObject (readonly)

Returns the value of attribute group.



6
7
8
# File 'lib/pgbouncerhero/database.rb', line 6

def group
  @group
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/pgbouncerhero/database.rb', line 6

def id
  @id
end

Instance Method Details

#connectionObject



19
20
21
# File 'lib/pgbouncerhero/database.rb', line 19

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

#dbnameObject



39
40
41
# File 'lib/pgbouncerhero/database.rb', line 39

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

#hostObject



23
24
25
# File 'lib/pgbouncerhero/database.rb', line 23

def host
  @url.host if @url
end

#nameObject



15
16
17
# File 'lib/pgbouncerhero/database.rb', line 15

def name
  @name ||= id.to_s
end

#passwordObject



35
36
37
# File 'lib/pgbouncerhero/database.rb', line 35

def password
  @url.password if @url
end

#portObject



27
28
29
# File 'lib/pgbouncerhero/database.rb', line 27

def port
  @url.port if @url
end

#userObject



31
32
33
# File 'lib/pgbouncerhero/database.rb', line 31

def user
  @url.user if @url
end