Class: Switches::Backends::Postgres::Connection
- Inherits:
-
Object
- Object
- Switches::Backends::Postgres::Connection
- Defined in:
- lib/switches/backends/postgres/connection.rb
Instance Method Summary collapse
- #close ⇒ Object
- #execute(query, *args) ⇒ Object
-
#initialize(uri) ⇒ Connection
constructor
A new instance of Connection.
- #listen(channel) ⇒ Object
- #notify(channel, payload) ⇒ Object
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
#close ⇒ Object
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, | yield 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 |