jetstream_bridge 1.14.0 → 1.15.0

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: 649a6258b0dce4c43433916df6bb2f9c5d41ba233f05ce66b935853b16637b64
4
- data.tar.gz: 942589e88710ac2da1651baa5cee79dbd2304db0fa15a12a8c9d911c8d05ef44
3
+ metadata.gz: 52de97c8d390176c6113c836f07126258f513ddf7feac51dd570d271a43f8ca5
4
+ data.tar.gz: 56a583ab2be2170e28afe5e1c89b33e51f8d40fa84dfb66b89666949e9390dc9
5
5
  SHA512:
6
- metadata.gz: 10540646b48b7d605f5f92915d4d8be5aed2f72578a151c3f2e4bc500a2908df4c216f1baa0dc128fddd502ca4f88ef73e6c27bb56ab9174573619a298893d4e
7
- data.tar.gz: 0debe41380866ee0253570f87b7a3f13dbdbdd3456cbc655815da586612d36155df1f169ba5f321f037b0031f50552f6e8d5e82b04f52f49b41f4e05eb1c1a40
6
+ metadata.gz: 64408358299860a7bb08897d8e0360e265274990499fe963cbd133a4592e186d71055814d9aeaf87b695b8035fab095a6f67ef99027135f9c7a5205e299be11e
7
+ data.tar.gz: 0bff44a878e9a78f8288c6aed2f9dd8319a249b8f6b1f3275666040f248999a5cfda73fbc5196f6641a84f52ffcad0eba001bc0ac71ab83e6b04c0ce21b8d8f2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jetstream_bridge (1.14.0)
4
+ jetstream_bridge (1.15.0)
5
5
  activerecord (>= 6.0)
6
6
  activesupport (>= 6.0)
7
7
  nats-pure (~> 2.4)
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'json'
4
+
3
5
  begin
4
6
  require 'active_record'
5
7
  rescue LoadError
@@ -15,6 +17,7 @@ module JetstreamBridge
15
17
  # Safe column presence check that never boots a connection during class load.
16
18
  def has_column?(name)
17
19
  return false unless ar_connected?
20
+
18
21
  connection.schema_cache.columns_hash(table_name).key?(name.to_s)
19
22
  rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::NoDatabaseError
20
23
  false
@@ -23,7 +26,7 @@ module JetstreamBridge
23
26
  def ar_connected?
24
27
  # Avoid creating a connection; rescue if pool isn't set yet.
25
28
  ActiveRecord::Base.connected? && connection_pool.active_connection?
26
- rescue
29
+ rescue StandardError
27
30
  false
28
31
  end
29
32
  end
@@ -42,11 +45,15 @@ module JetstreamBridge
42
45
  # Fallback legacy fields when event_id is absent
43
46
  validates :resource_type,
44
47
  presence: true,
45
- if: -> { !self.class.has_column?(:event_id) && self.class.has_column?(:resource_type) }
48
+ if: lambda {
49
+ !self.class.has_column?(:event_id) && self.class.has_column?(:resource_type)
50
+ }
46
51
 
47
52
  validates :resource_id,
48
53
  presence: true,
49
- if: -> { !self.class.has_column?(:event_id) && self.class.has_column?(:resource_id) }
54
+ if: lambda {
55
+ !self.class.has_column?(:event_id) && self.class.has_column?(:resource_id)
56
+ }
50
57
 
51
58
  validates :event_type,
52
59
  presence: true,
@@ -63,9 +70,9 @@ module JetstreamBridge
63
70
  # ---- Defaults that do not require schema at load time ----
64
71
  before_validation do
65
72
  now = Time.now.utc
66
- self.status ||= 'pending' if self.class.has_column?(:status) && status.blank?
67
- self.enqueued_at ||= now if self.class.has_column?(:enqueued_at) && enqueued_at.blank?
68
- self.attempts = 0 if self.class.has_column?(:attempts) && attempts.nil?
73
+ self.status ||= 'pending' if self.class.has_column?(:status) && status.blank?
74
+ self.enqueued_at ||= now if self.class.has_column?(:enqueued_at) && enqueued_at.blank?
75
+ self.attempts = 0 if self.class.has_column?(:attempts) && attempts.nil?
69
76
  end
70
77
 
71
78
  # ---- Helpers ----
@@ -85,9 +92,14 @@ module JetstreamBridge
85
92
  def payload_hash
86
93
  v = self[:payload]
87
94
  case v
88
- when String then JSON.parse(v) rescue {}
89
- when Hash then v
90
- else v.respond_to?(:as_json) ? v.as_json : {}
95
+ when String then begin
96
+ JSON.parse(v)
97
+ rescue StandardError
98
+ {}
99
+ end
100
+ when Hash then v
101
+ else
102
+ v.respond_to?(:as_json) ? v.as_json : {}
91
103
  end
92
104
  end
93
105
  end
@@ -99,15 +111,17 @@ module JetstreamBridge
99
111
  raise_missing_ar!('Outbox', method_name)
100
112
  end
101
113
 
102
- def respond_to_missing?(_m, _p = false) = false
114
+ def respond_to_missing?(_m, _p = false)
115
+ false
116
+ end
103
117
 
104
118
  private
105
119
 
106
120
  def raise_missing_ar!(which, method_name)
107
121
  raise(
108
122
  "#{which} requires ActiveRecord (tried to call ##{method_name}). " \
109
- 'Enable `use_outbox` only in apps with ActiveRecord, or add ' \
110
- '`gem "activerecord"` to your Gemfile.'
123
+ 'Enable `use_outbox` only in apps with ActiveRecord, or add ' \
124
+ '`gem "activerecord"` to your Gemfile.'
111
125
  )
112
126
  end
113
127
  end
@@ -4,5 +4,5 @@
4
4
  #
5
5
  # Version constant for the gem.
6
6
  module JetstreamBridge
7
- VERSION = '1.14.0'
7
+ VERSION = '1.15.0'
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jetstream_bridge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.14.0
4
+ version: 1.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Attara