pgbus 0.9.3 → 0.9.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/pgbus/streams/broadcastable_override.rb +42 -9
- data/lib/pgbus/streams/turbo_broadcastable.rb +6 -1
- data/lib/pgbus/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8f659edeb84f108e166ae2ea981e5eb3e4fabfde1542769a777d9d707aba349d
|
|
4
|
+
data.tar.gz: 2abf0072cdc0f414670367e4a59881003285c43f895618d1ec63b1b7fca5e27a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c527aa3c60ae917b2589cd23b99f14348fa4eef752ae004b2ffc3a90d248e5c09bc68ee06ddfde3d335c469192dd821551b56bb9b6fb259f6f1b961a61567d9e
|
|
7
|
+
data.tar.gz: 6f66d58dfe49bca18d3b3a1379e2c458c75954cec3c7fb1ddd23fcfa05e495b00db4d3646d42e32e40b202135e5bb7e51a18d6287ab897e7605fd87250c93391
|
|
@@ -36,17 +36,23 @@ module Pgbus
|
|
|
36
36
|
broadcast_action_to
|
|
37
37
|
].freeze
|
|
38
38
|
|
|
39
|
+
# pgbus-specific broadcast options that Turbo's own broadcast helpers
|
|
40
|
+
# don't understand. We pull them out of kwargs (so they never reach
|
|
41
|
+
# turbo-rails' renderer) and thread them to broadcast_stream_to via
|
|
42
|
+
# thread-locals, mirroring the original durable: shim.
|
|
43
|
+
PGBUS_BROADCAST_OPTS = %i[durable exclude visible_to event].freeze
|
|
44
|
+
|
|
39
45
|
BROADCAST_METHODS.each do |method_name|
|
|
40
46
|
define_method(method_name) do |*streamables, **kwargs|
|
|
41
|
-
|
|
42
|
-
|
|
47
|
+
opts = extract_pgbus_broadcast_opts(kwargs)
|
|
48
|
+
with_pgbus_broadcast_opts(**opts) { super(*streamables, **kwargs) }
|
|
43
49
|
end
|
|
44
50
|
end
|
|
45
51
|
|
|
46
52
|
BROADCAST_ACTION_METHODS.each do |method_name|
|
|
47
53
|
define_method(method_name) do |*streamables, action:, **kwargs|
|
|
48
|
-
|
|
49
|
-
|
|
54
|
+
opts = extract_pgbus_broadcast_opts(kwargs)
|
|
55
|
+
with_pgbus_broadcast_opts(**opts) { super(*streamables, action: action, **kwargs) }
|
|
50
56
|
end
|
|
51
57
|
end
|
|
52
58
|
|
|
@@ -121,14 +127,41 @@ module Pgbus
|
|
|
121
127
|
|
|
122
128
|
private
|
|
123
129
|
|
|
124
|
-
def
|
|
125
|
-
|
|
130
|
+
def extract_pgbus_broadcast_opts(kwargs)
|
|
131
|
+
PGBUS_BROADCAST_OPTS.each_with_object({}) do |key, opts|
|
|
132
|
+
opts[key] = kwargs.delete(key) if kwargs.key?(key)
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Set the pgbus broadcast thread-locals for the duration of the block,
|
|
137
|
+
# restoring previous values afterwards (nested/concurrent-safe). Only
|
|
138
|
+
# keys actually passed are touched, so unrelated outer broadcasts keep
|
|
139
|
+
# their values.
|
|
140
|
+
def with_pgbus_broadcast_opts(durable: :__unset__, exclude: :__unset__, visible_to: :__unset__, event: :__unset__)
|
|
141
|
+
previous = {}
|
|
142
|
+
set = lambda do |tl_key, value|
|
|
143
|
+
next if value == :__unset__
|
|
144
|
+
|
|
145
|
+
previous[tl_key] = Thread.current[tl_key]
|
|
146
|
+
Thread.current[tl_key] = value
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
set.call(:pgbus_broadcast_durable, durable)
|
|
150
|
+
set.call(:pgbus_broadcast_exclude, exclude)
|
|
151
|
+
set.call(:pgbus_broadcast_visible_to, visible_to)
|
|
152
|
+
set.call(:pgbus_broadcast_event, event)
|
|
126
153
|
|
|
127
|
-
previous = Thread.current[:pgbus_broadcast_durable]
|
|
128
|
-
Thread.current[:pgbus_broadcast_durable] = value
|
|
129
154
|
yield
|
|
130
155
|
ensure
|
|
131
|
-
Thread.current[
|
|
156
|
+
previous.each { |tl_key, value| Thread.current[tl_key] = value }
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# Kept for backward compatibility — the class-level durable callbacks
|
|
160
|
+
# (broadcasts_to with durable:) and any external callers may still use it.
|
|
161
|
+
def with_pgbus_durable(value, &)
|
|
162
|
+
return yield if value.nil?
|
|
163
|
+
|
|
164
|
+
with_pgbus_broadcast_opts(durable: value, &)
|
|
132
165
|
end
|
|
133
166
|
end
|
|
134
167
|
end
|
|
@@ -42,7 +42,12 @@ module Pgbus
|
|
|
42
42
|
else
|
|
43
43
|
override
|
|
44
44
|
end
|
|
45
|
-
Pgbus.stream(name, durable: durable).broadcast(
|
|
45
|
+
Pgbus.stream(name, durable: durable).broadcast(
|
|
46
|
+
content,
|
|
47
|
+
exclude: Thread.current[:pgbus_broadcast_exclude],
|
|
48
|
+
visible_to: Thread.current[:pgbus_broadcast_visible_to],
|
|
49
|
+
event: Thread.current[:pgbus_broadcast_event]
|
|
50
|
+
)
|
|
46
51
|
end
|
|
47
52
|
end
|
|
48
53
|
|
data/lib/pgbus/version.rb
CHANGED