deimos-ruby 2.3.0 → 2.3.1

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: 9811f05eec0d9b6777e2ed047a2e81b0a23bd770b52866bf8c8a79f84c8ec586
4
- data.tar.gz: c84cba2ecf750f4349ba86e47ddab2d01a4dd8e5f8fd9ab008b3fcfeb14b1425
3
+ metadata.gz: ce1117d7a1d29304fcb0cafca935db90c4378ceaf9aa089dfcf9fa56fe5ea25d
4
+ data.tar.gz: 964f517ef411af2dcb3dbbc9f6e507d34fefcac6ef9321b8937d686bd3e307b7
5
5
  SHA512:
6
- metadata.gz: b8319ada2f2b715e750e7de5caf6c6117d6154da6277988e12851f420c69a2f3adc0ab30594a23bca86ec8ffa57ef2cc3e5ab9758421e26fbe91cf682ad28e04
7
- data.tar.gz: 2174b8d776b547689422d6af381f423680d61df368be813e53f213eb8d084971b338a3382d8775e07ef324b9443fc1f5427fed834c54629d52c88728d016fd49
6
+ metadata.gz: 5684bbf8cc1e2a0831369b47f28ffb84795a3d21a47b1b11d159b2909e9af36fd83b1756a47a9902d04c792a0a389cb8d675e0451f50e75c7d8c3ccf50a389ac
7
+ data.tar.gz: 9946b5a3ceeae405778731c82e1bfcc24dfae89a19bb0b2553620446815b712abc81a2bb9303e31ecb1d8d7aa68c3856df6cb2c46c1264f3305e6dbe0e3b530b
data/CHANGELOG.md CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 2.3.1 - 2026-01-22
11
+
12
+ - Feature: Allow strings to be used in the `record_class` declaration.
13
+
10
14
  # 2.3.0 - 2026-01-13
11
15
 
12
16
  - Feature: Support broker setting per topic in producer configs.
data/README.md CHANGED
@@ -398,6 +398,8 @@ class MyProducer < Deimos::ActiveRecordProducer
398
398
  # using the default functionality and don't need to override it)
399
399
  # by setting `refetch` to false. This will avoid extra database fetches.
400
400
  record_class Widget, refetch: false
401
+
402
+ # You can use a string here instead to avoid eager loading: record_class 'Widget'
401
403
 
402
404
  # Optionally override this if you want the message to be
403
405
  # sent even if fields that aren't in the schema are changed.
@@ -485,6 +487,7 @@ A sample consumer would look as follows:
485
487
  ```ruby
486
488
  class MyConsumer < Deimos::ActiveRecordConsumer
487
489
  record_class Widget
490
+ # or use a string: record_class 'Widget'
488
491
 
489
492
  # Optional override of the way to fetch records based on payload and
490
493
  # key. Default is to use the key to search the primary key of the table.
@@ -562,6 +565,7 @@ A sample batch consumer would look as follows:
562
565
  ```ruby
563
566
  class MyConsumer < Deimos::ActiveRecordConsumer
564
567
  record_class Widget
568
+ # or use a string: record_class 'Widget'
565
569
 
566
570
  # Controls whether the batch is compacted before consuming.
567
571
  # If true, only the last message for each unique key in a batch will be
@@ -72,6 +72,7 @@ module Deimos
72
72
  # Setup
73
73
  def initialize
74
74
  @klass = self.class.config[:record_class]
75
+ @klass = @klass.constantize if @klass.is_a?(String)
75
76
  @compacted = self.class.config[:compacted] != false
76
77
  end
77
78
 
@@ -13,18 +13,24 @@ module Deimos
13
13
  class ActiveRecordProducer < Producer
14
14
  class << self
15
15
  # Indicate the class this producer is working on.
16
- # @param klass [Class]
16
+ # @param klass [Class,String]
17
17
  # @param refetch [Boolean] if true, and we are given a hash instead of
18
18
  # a record object, refetch the record to pass into the `generate_payload`
19
19
  # method.
20
20
  # @return [void]
21
21
  def record_class(klass=nil, refetch: true)
22
- return @record_class if klass.nil?
22
+ return record_klass if klass.nil?
23
23
 
24
24
  @record_class = klass
25
25
  @refetch_record = refetch
26
26
  end
27
27
 
28
+ # @return [Class,nil]
29
+ def record_klass
30
+ @record_class = @record_class.constantize if @record_class.is_a?(String)
31
+ @record_class
32
+ end
33
+
28
34
  # @param record [ActiveRecord::Base]
29
35
  # @param force_send [Boolean]
30
36
  # @return [void]
@@ -38,14 +44,14 @@ module Deimos
38
44
  def send_events(records, force_send: false)
39
45
  return if Deimos.producers_disabled?(self)
40
46
 
41
- primary_key = @record_class&.primary_key
47
+ primary_key = record_klass&.primary_key
42
48
  messages = records.map do |record|
43
49
  if record.respond_to?(:attributes)
44
50
  attrs = record.attributes.with_indifferent_access
45
51
  else
46
52
  attrs = record.with_indifferent_access
47
53
  if @refetch_record && attrs[primary_key]
48
- record = @record_class.find(attrs[primary_key])
54
+ record = record_klass.find(attrs[primary_key])
49
55
  end
50
56
  end
51
57
  generate_payload(attrs, record).with_indifferent_access
@@ -96,7 +102,7 @@ module Deimos
96
102
  # than this value).
97
103
  # @return [ActiveRecord::Relation]
98
104
  def poll_query(time_from:, time_to:, min_id:, column_name: :updated_at)
99
- klass = @record_class
105
+ klass = record_klass
100
106
  table = ActiveRecord::Base.connection.quote_table_name(klass.table_name)
101
107
  column = ActiveRecord::Base.connection.quote_column_name(column_name)
102
108
  primary = ActiveRecord::Base.connection.quote_column_name(klass.primary_key)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Deimos
4
- VERSION = '2.3.0'
4
+ VERSION = '2.3.1'
5
5
  end
@@ -70,7 +70,7 @@ module ActiveRecordBatchConsumerTest # rubocop:disable Metrics/ModuleLength
70
70
  end
71
71
 
72
72
  before(:each) do
73
- ActiveRecord::Base.connection.truncate_tables(%i(widgets details locales))
73
+ ActiveRecord::Base.connection.truncate_tables(:widgets, :details, :locales)
74
74
  Widget.create!(test_id: 'bad_id', some_int: 100) # should not show up
75
75
  end
76
76
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deimos-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.0
4
+ version: 2.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner