class Switches::Backends::Postgres::Connection
Public Class Methods
new(uri)
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 5 def initialize(uri) @uri = URI(uri) end
Public Instance Methods
close()
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 27 def close connection.close end
execute(query, *args)
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 9 def execute(query, *args) connection.exec(query, args) end
listen(channel) { |message| ... }
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 13 def listen(channel) connection.exec("LISTEN #{channel}") loop do connection.wait_for_notify do |event, pid, message| yield message end end end
notify(channel, payload)
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 23 def notify(channel, payload) connection.exec("NOTIFY #{channel}, '#{payload}'") end
Private Instance Methods
connection()
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 33 def connection @connection ||= PG.connect(connection_options) end
connection_options()
click to toggle source
# File lib/switches/backends/postgres/connection.rb, line 37 def connection_options { user: @uri.user, password: @uri.password, host: @uri.host, port: @uri.port, dbname: @uri.path[1..-1] } end