Class: Switches::Backends::Postgres
- Inherits:
-
Object
- Object
- Switches::Backends::Postgres
show all
- Defined in:
- lib/switches/backends/postgres.rb,
lib/switches/backends/postgres/table.rb,
lib/switches/backends/postgres/connection.rb,
lib/switches/backends/postgres/tasks/setup.rb,
lib/switches/backends/postgres/tasks/remove.rb
Defined Under Namespace
Classes: Connection, Remove, Setup, Table
Constant Summary
collapse
- CHANNEL =
"switches"
- TABLE =
"switches"
Instance Method Summary
collapse
Constructor Details
#initialize(uri, instance) ⇒ Postgres
Returns a new instance of Postgres.
11
12
13
14
|
# File 'lib/switches/backends/postgres.rb', line 11
def initialize(uri, instance)
@uri = uri
@instance = instance
end
|
Instance Method Details
#clear ⇒ Object
34
35
36
|
# File 'lib/switches/backends/postgres.rb', line 34
def clear
table.clear
end
|
#get(item) ⇒ Object
20
21
22
23
24
|
# File 'lib/switches/backends/postgres.rb', line 20
def get(item)
if result = table.find(item.key)
JSONSerializer.deserialize(result)
end
end
|
#listen ⇒ Object
26
27
28
|
# File 'lib/switches/backends/postgres.rb', line 26
def listen
@thread ||= Thread.new { subscribe }
end
|
#notify(update) ⇒ Object
30
31
32
|
# File 'lib/switches/backends/postgres.rb', line 30
def notify(update)
connection.notify(CHANNEL, update.to_json)
end
|
#set(item) ⇒ Object
16
17
18
|
# File 'lib/switches/backends/postgres.rb', line 16
def set(item)
table.upsert(item.key, item.to_json)
end
|
#stop ⇒ Object
38
39
40
41
42
|
# File 'lib/switches/backends/postgres.rb', line 38
def stop
listen.kill
listener.close
connection.close
end
|