celluloid-io-pg-listener 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/celluloid-io-pg-listener/client.rb +12 -0
- data/lib/celluloid-io-pg-listener/examples/client.rb +5 -5
- data/lib/celluloid-io-pg-listener/initialization/async_listener.rb +3 -3
- data/lib/celluloid-io-pg-listener/initialization/client_extracted_signature.rb +4 -4
- data/lib/celluloid-io-pg-listener/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6a79efd0a0cd022732811b9367802aea69dddf9
|
4
|
+
data.tar.gz: c9a7c4ad7444168edffcc1b6ea49c76268ed32b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e19ab96333005f80c89aab088fda6ebd361e5d8b8c66636bf33a22e48e8c21f25d684b8f442273c52b631134ea3dfc02fad7472592ef503cace0dbba1f04ed9
|
7
|
+
data.tar.gz: 217fac620e3848f6ff4e74f13e06c2bd9d439e97b8a7095b4aa42eebc6adae7914053d269f3950618826bea06682196c20a215dafbb9ea534a6f07323e953ed6
|
@@ -13,6 +13,18 @@ module CelluloidIOPGListener
|
|
13
13
|
base.prepend CelluloidIOPGListener::Initialization::ArgumentExtraction
|
14
14
|
end
|
15
15
|
|
16
|
+
# Defining initialize in a class including this module is optional,
|
17
|
+
# unless you have custom args you need to handle
|
18
|
+
# aside from those used by the CelluloidIOPGListener::Client
|
19
|
+
# But if you do define it, use a splat,
|
20
|
+
# hash or array splat should work,
|
21
|
+
# depending on your signature needs.
|
22
|
+
# With either splat, only pass the splat params to super,
|
23
|
+
# and handle all your custom params locally.
|
24
|
+
#
|
25
|
+
def initialize(*args)
|
26
|
+
end
|
27
|
+
|
16
28
|
def unlisten_wrapper(channel, payload, &block)
|
17
29
|
if block_given?
|
18
30
|
debug "Acting on payload: #{payload} on #{channel}"
|
@@ -4,6 +4,7 @@ module CelluloidIOPGListener
|
|
4
4
|
|
5
5
|
include CelluloidIOPGListener::Client
|
6
6
|
|
7
|
+
attr_reader :optional_arg
|
7
8
|
# Defining initialize is optional,
|
8
9
|
# unless you have custom args you need to handle
|
9
10
|
# aside from those used by the CelluloidIOPGListener::Client
|
@@ -11,12 +12,11 @@ module CelluloidIOPGListener
|
|
11
12
|
# hash or array splat should work,
|
12
13
|
# depending on your signature needs.
|
13
14
|
# With either splat, only pass the splat params to super,
|
14
|
-
# and handle all
|
15
|
+
# and handle all your custom params locally.
|
15
16
|
#
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
# end
|
17
|
+
def initialize(optional_arg = nil, *options)
|
18
|
+
@optional_arg = optional_arg # handle it here, don't pass it on!
|
19
|
+
end
|
20
20
|
|
21
21
|
def insert_callback(channel, payload)
|
22
22
|
# <-- within the unlisten_wrapper's block if :insert_callback is the callback_method
|
@@ -9,11 +9,11 @@ module CelluloidIOPGListener
|
|
9
9
|
def initialize(*args)
|
10
10
|
hash_arg = args.last.is_a?(Hash) ? args.pop : {}
|
11
11
|
warn "[#{self.class}] You have not specified a callback_method, so :unlisten_wrapper will be used." unless hash_arg[:callback_method]
|
12
|
-
@callback_method = hash_arg
|
12
|
+
@callback_method = hash_arg[:callback_method] = hash_arg[:callback_method] || :unlisten_wrapper
|
13
13
|
# Doesn't appear to be any other way to make it work with subclassing,
|
14
14
|
# due to the way Celluloid Proxies the class, and hijacks the inheritance chains
|
15
|
-
subclassed_client = hash_arg
|
16
|
-
args << hash_arg
|
15
|
+
subclassed_client = hash_arg[:subclassed_client] = hash_arg[:subclassed_client] || false
|
16
|
+
args << hash_arg
|
17
17
|
|
18
18
|
enhance_callback_method unless @callback_method == :unlisten_wrapper
|
19
19
|
|
@@ -25,14 +25,14 @@ module CelluloidIOPGListener
|
|
25
25
|
def initialize(*args)
|
26
26
|
hash_arg = args.last.is_a?(Hash) ? args.pop : {}
|
27
27
|
# Extract the channel first, as it is required
|
28
|
-
@channel = hash_arg
|
28
|
+
@channel = hash_arg[:channel] || raise(ArgumentError, "[#{self.class}] :channel is required, but got #{args} and #{hash_arg}")
|
29
29
|
# Extract the args for PG.connect
|
30
30
|
@conninfo_hash = (hash_arg.keys & KEYS).
|
31
|
-
each_with_object({}) { |k,h| h.update(k => hash_arg
|
31
|
+
each_with_object({}) { |k,h| h.update(k => hash_arg[k]) }.
|
32
32
|
# Future proof. Provide a way to send in any PG.connect() options not explicitly defined in KEYS
|
33
|
-
merge(hash_arg
|
33
|
+
merge(hash_arg[:conninfo_hash] || {})
|
34
34
|
# Add any other named parameters back to the args for super
|
35
|
-
args << hash_arg
|
35
|
+
args << hash_arg
|
36
36
|
@super_signature = args
|
37
37
|
end
|
38
38
|
|