deimos-ruby 2.0.3 → 2.0.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/CHANGELOG.md +4 -0
- data/docs/CONFIGURATION.md +6 -5
- data/lib/deimos/config/configuration.rb +4 -0
- data/lib/deimos/kafka_source.rb +14 -4
- data/lib/deimos/version.rb +1 -1
- data/spec/kafka_source_spec.rb +49 -1
- metadata +2 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 277d2715eefd6d0ddc262ee4e514fe3df2542aacf13c60854f66f326a46664ae
         | 
| 4 | 
            +
              data.tar.gz: 6a5b890b14258eeba1d08b9e84f146030a7c9f37784008a8840311dbafca49a1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: e8c0f52c88c5106c8a22acb6a15f7e850b307aa8e34aa5ac5cc140a1bd7d10cebc891ad5ac26d386ecc8f76e080c53791e9a5d841dc1db56a170df49fc596daf
         | 
| 7 | 
            +
              data.tar.gz: b2f50f1d14dd55330a78159645bc335e82217ce59284066cd02f37e98cc66d932bf8ff78ae54d01f942602cf1759ab513239a90898042a400d4047c55dbc11e2
         | 
    
        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.0.4 - 2025-03-17
         | 
| 11 | 
            +
             | 
| 12 | 
            +
            - Feature: Added `producers.truncate_columns` config.
         | 
| 13 | 
            +
             | 
| 10 14 | 
             
            ## 2.0.3 - 2025-03-12
         | 
| 11 15 | 
             
            - Fix: `ActiveRecordProducer.config` could crash if there were non-producer configs.
         | 
| 12 16 |  | 
    
        data/docs/CONFIGURATION.md
    CHANGED
    
    | @@ -43,11 +43,12 @@ things you need to reference into local variables before calling `configure`. | |
| 43 43 |  | 
| 44 44 | 
             
            ### Producer Configuration
         | 
| 45 45 |  | 
| 46 | 
            -
            | Config name | 
| 47 | 
            -
             | 
| 48 | 
            -
            | producers.topic_prefix | 
| 49 | 
            -
            | producers.disabled | 
| 50 | 
            -
            | producers.backend | 
| 46 | 
            +
            | Config name                | Default        | Description                                                                                                                                                                                    |
         | 
| 47 | 
            +
            |----------------------------|----------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
         | 
| 48 | 
            +
            | producers.topic_prefix     | nil            | Add a prefix to all topic names. This can be useful if you're using the same Kafka broker for different environments that are producing the same topics.                                       |
         | 
| 49 | 
            +
            | producers.disabled         | false          | Disable all actual message producing. Generally more useful to use the `disable_producers` method instead.                                                                                     |
         | 
| 50 | 
            +
            | producers.backend          | `:kafka_async` | Currently can be set to `:db`, `:kafka`, or `:kafka_async`. If using Kafka directly, a good pattern is to set to async in your user-facing app, and sync in your consumers or delayed workers. |
         | 
| 51 | 
            +
            | producers.truncate_columns | false          | If set to true, will truncate values to their database limits when using KafkaSource.                                                                                                          |
         | 
| 51 52 |  | 
| 52 53 | 
             
            ### Schema Configuration
         | 
| 53 54 |  | 
| @@ -133,6 +133,10 @@ module Deimos # rubocop:disable Metrics/ModuleLength | |
| 133 133 | 
             
                  # sync in your consumers or delayed workers.
         | 
| 134 134 | 
             
                  # @return [Symbol]
         | 
| 135 135 | 
             
                  setting :backend, :kafka_async
         | 
| 136 | 
            +
             | 
| 137 | 
            +
                  # If set to true, KafkaSource will automatically truncate fields to match the column
         | 
| 138 | 
            +
                  # length in the database.
         | 
| 139 | 
            +
                  setting :truncate_columns
         | 
| 136 140 | 
             
                end
         | 
| 137 141 |  | 
| 138 142 | 
             
                setting :schema do
         | 
    
        data/lib/deimos/kafka_source.rb
    CHANGED
    
    | @@ -6,10 +6,6 @@ module Deimos | |
| 6 6 | 
             
              module KafkaSource
         | 
| 7 7 | 
             
                extend ActiveSupport::Concern
         | 
| 8 8 |  | 
| 9 | 
            -
                # @return [String]
         | 
| 10 | 
            -
                DEPRECATION_WARNING = 'The kafka_producer interface will be deprecated ' \
         | 
| 11 | 
            -
                    'in future releases. Please use kafka_producers instead.'
         | 
| 12 | 
            -
             | 
| 13 9 | 
             
                included do
         | 
| 14 10 | 
             
                  after_create(:send_kafka_event_on_create)
         | 
| 15 11 | 
             
                  after_update(:send_kafka_event_on_update)
         | 
| @@ -22,6 +18,7 @@ module Deimos | |
| 22 18 | 
             
                  return unless self.persisted?
         | 
| 23 19 | 
             
                  return unless self.class.kafka_config[:create]
         | 
| 24 20 |  | 
| 21 | 
            +
                  self.truncate_columns if Deimos.config.producers.truncate_columns
         | 
| 25 22 | 
             
                  self.class.kafka_producers.each { |p| p.send_event(self) }
         | 
| 26 23 | 
             
                end
         | 
| 27 24 |  | 
| @@ -39,6 +36,7 @@ module Deimos | |
| 39 36 | 
             
                    field_change.present? && field_change[0] != field_change[1]
         | 
| 40 37 | 
             
                  end
         | 
| 41 38 | 
             
                  return unless any_changes
         | 
| 39 | 
            +
                  self.truncate_columns if Deimos.config.producers.truncate_columns
         | 
| 42 40 |  | 
| 43 41 | 
             
                  producers.each { |p| p.send_event(self) }
         | 
| 44 42 | 
             
                end
         | 
| @@ -124,5 +122,17 @@ module Deimos | |
| 124 122 | 
             
                    results
         | 
| 125 123 | 
             
                  end
         | 
| 126 124 | 
             
                end
         | 
| 125 | 
            +
             | 
| 126 | 
            +
                # check if any field has value longer than the field limit
         | 
| 127 | 
            +
                def truncate_columns
         | 
| 128 | 
            +
                  self.class.columns.each do |col|
         | 
| 129 | 
            +
                    next unless col.type == :string
         | 
| 130 | 
            +
                    next if self[col.name].blank?
         | 
| 131 | 
            +
                    if self[col.name].to_s.length > col.limit
         | 
| 132 | 
            +
                      self[col.name] = self[col.name][0..col.limit - 1]
         | 
| 133 | 
            +
                    end
         | 
| 134 | 
            +
                  end
         | 
| 135 | 
            +
                  false
         | 
| 136 | 
            +
                end
         | 
| 127 137 | 
             
              end
         | 
| 128 138 | 
             
            end
         | 
    
        data/lib/deimos/version.rb
    CHANGED
    
    
    
        data/spec/kafka_source_spec.rb
    CHANGED
    
    | @@ -10,7 +10,7 @@ module KafkaSourceSpec | |
| 10 10 | 
             
                    t.integer(:widget_id)
         | 
| 11 11 | 
             
                    t.string(:description)
         | 
| 12 12 | 
             
                    t.string(:model_id, default: '')
         | 
| 13 | 
            -
                    t.string(:name)
         | 
| 13 | 
            +
                    t.string(:name, limit: 100)
         | 
| 14 14 | 
             
                    t.timestamps
         | 
| 15 15 | 
             
                  end
         | 
| 16 16 | 
             
                  ActiveRecord::Base.connection.add_index(:widgets, :widget_id)
         | 
| @@ -105,6 +105,54 @@ module KafkaSourceSpec | |
| 105 105 | 
             
                  expect('my-topic-the-second').to have_sent(nil, widget.id)
         | 
| 106 106 | 
             
                end
         | 
| 107 107 |  | 
| 108 | 
            +
                context 'with truncation off' do
         | 
| 109 | 
            +
                  before(:each) do
         | 
| 110 | 
            +
                    Deimos.config.producers.truncate_columns = false
         | 
| 111 | 
            +
                  end
         | 
| 112 | 
            +
                  it 'should not truncate values' do
         | 
| 113 | 
            +
                    widget = Widget.create!(widget_id: 1, name: 'a'*500)
         | 
| 114 | 
            +
                    expect('my-topic').to have_sent({
         | 
| 115 | 
            +
                                                      widget_id: 1,
         | 
| 116 | 
            +
                                                      name: 'a'*500,
         | 
| 117 | 
            +
                                                      id: widget.id,
         | 
| 118 | 
            +
                                                      created_at: anything,
         | 
| 119 | 
            +
                                                      updated_at: anything
         | 
| 120 | 
            +
                                                    }, 1)
         | 
| 121 | 
            +
                    widget.update_attribute(:name, 'b'*500)
         | 
| 122 | 
            +
                    expect('my-topic').to have_sent({
         | 
| 123 | 
            +
                                                      widget_id: 1,
         | 
| 124 | 
            +
                                                      name: 'b'*500,
         | 
| 125 | 
            +
                                                      id: widget.id,
         | 
| 126 | 
            +
                                                      created_at: anything,
         | 
| 127 | 
            +
                                                      updated_at: anything
         | 
| 128 | 
            +
                                                    }, 1)
         | 
| 129 | 
            +
                  end
         | 
| 130 | 
            +
                end
         | 
| 131 | 
            +
             | 
| 132 | 
            +
                context 'with truncation on' do
         | 
| 133 | 
            +
                  before(:each) do
         | 
| 134 | 
            +
                    Deimos.config.producers.truncate_columns = true
         | 
| 135 | 
            +
                  end
         | 
| 136 | 
            +
                  it 'should truncate values' do
         | 
| 137 | 
            +
                    widget = Widget.create!(widget_id: 1, name: 'a'*500)
         | 
| 138 | 
            +
                    expect('my-topic').to have_sent({
         | 
| 139 | 
            +
                                                      widget_id: 1,
         | 
| 140 | 
            +
                                                      name: 'a'*100,
         | 
| 141 | 
            +
                                                      id: widget.id,
         | 
| 142 | 
            +
                                                      created_at: anything,
         | 
| 143 | 
            +
                                                      updated_at: anything
         | 
| 144 | 
            +
                                                    }, 1)
         | 
| 145 | 
            +
                    widget.update_attribute(:name, 'b'*500)
         | 
| 146 | 
            +
                    expect('my-topic').to have_sent({
         | 
| 147 | 
            +
                                                      widget_id: 1,
         | 
| 148 | 
            +
                                                      name: 'b'*100,
         | 
| 149 | 
            +
                                                      id: widget.id,
         | 
| 150 | 
            +
                                                      created_at: anything,
         | 
| 151 | 
            +
                                                      updated_at: anything
         | 
| 152 | 
            +
                                                    }, 1)
         | 
| 153 | 
            +
                  end
         | 
| 154 | 
            +
                end
         | 
| 155 | 
            +
             | 
| 108 156 | 
             
                it 'should send events on import' do
         | 
| 109 157 | 
             
                  widgets = (1..3).map do |i|
         | 
| 110 158 | 
             
                    Widget.new(widget_id: i, name: "Widget #{i}")
         | 
    
        metadata
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: deimos-ruby
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 2.0. | 
| 4 | 
            +
              version: 2.0.4
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Daniel Orner
         | 
| 8 8 | 
             
            autorequire:
         | 
| 9 9 | 
             
            bindir: bin
         | 
| 10 10 | 
             
            cert_chain: []
         | 
| 11 | 
            -
            date: 2025-03- | 
| 11 | 
            +
            date: 2025-03-17 00:00:00.000000000 Z
         | 
| 12 12 | 
             
            dependencies:
         | 
| 13 13 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 14 14 | 
             
              name: avro_turf
         |