Class: Switches::Backends::Postgres::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/switches/backends/postgres/connection.rb

Instance Method Summary collapse

Constructor Details

#initialize(uri) ⇒ Connection

Returns a new instance of Connection.



5
6
7
# File 'lib/switches/backends/postgres/connection.rb', line 5

def initialize(uri)
  @uri = URI(uri)
end

Instance Method Details

#closeObject



27
28
29
# File 'lib/switches/backends/postgres/connection.rb', line 27

def close
  connection.close
end

#execute(query, *args) ⇒ Object



9
10
11
# File 'lib/switches/backends/postgres/connection.rb', line 9

def execute(query, *args)
  connection.exec(query, args)
end

#listen(channel) ⇒ Object



13
14
15
16
17
18
19
20
21
# 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) ⇒ Object



23
24
25
# File 'lib/switches/backends/postgres/connection.rb', line 23

def notify(channel, payload)
  connection.exec("NOTIFY #{channel}, '#{payload}'")
end