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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 562d32e977685559437bdb1d3817fd02feb4fd9485b9101241a64d25d37162b1
4
- data.tar.gz: eeacf0de199bfdc49c5b68523c5bbae7b1eff7970637742f3ec3e4391e4a3b06
3
+ metadata.gz: 8f659edeb84f108e166ae2ea981e5eb3e4fabfde1542769a777d9d707aba349d
4
+ data.tar.gz: 2abf0072cdc0f414670367e4a59881003285c43f895618d1ec63b1b7fca5e27a
5
5
  SHA512:
6
- metadata.gz: a06cdb8eeecef32d6fa024f1fadac4f8c22758a11c91b1e9f5b00266869ea92b068c58a239a543c9409375d7155a59a5ec05f17cad59d7a23a49c90ecf74d7cd
7
- data.tar.gz: e2a941feb09d3462bb9a83cda9b48821cf93649b53e9e7305af4a3b43b95bccca7690f40ebcb42857c4b9118ebeb592bcfacc317302e3a71b39be1c4f78493aa
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
- durable = kwargs.delete(:durable)
42
- with_pgbus_durable(durable) { super(*streamables, **kwargs) }
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
- durable = kwargs.delete(:durable)
49
- with_pgbus_durable(durable) { super(*streamables, action: action, **kwargs) }
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 with_pgbus_durable(value)
125
- return yield if value.nil?
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[:pgbus_broadcast_durable] = previous unless value.nil?
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(content)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pgbus
4
- VERSION = "0.9.3"
4
+ VERSION = "0.9.4"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pgbus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.3
4
+ version: 0.9.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson