diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 693cb7d..89c323b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["3.0", "3.1", "3.2", "3.3"] + ruby: ["3.1", "3.2", "3.3"] name: ${{ matrix.ruby }} diff --git a/.rubocop.yml b/.rubocop.yml index 5869bb4..d0bf944 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,7 +2,7 @@ inherit_gem: rubocop-config-umbrellio: lib/rubocop.yml AllCops: - TargetRubyVersion: 3.0 + TargetRubyVersion: 3.1 Include: - bin/* - lib/**/*.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 86d0a43..6aa1f92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,18 @@ # Changelog All notable changes to this project will be documented in this file. +## [6.6.0] - 2024-12-06 +### Added +- Add custom version attributes +- Set table_name and schema_name as required for TableSync::Publishing::Raw + +### Changed +- `rabbit_messaging` gem version is locked on `~> 1.1.0` in order to provide a way to keep "up-to-date" + the actual rabbit_messaging gem version on our projects with table_sync update; + +### Removed +- Remove ruby 3.0 from ci workflow + ## [6.5.0] - 2024-03-19 ### Added - Add ruby 3.3 to ci workflow diff --git a/Gemfile.lock b/Gemfile.lock index 546e58b..5cb3b7d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,44 +1,44 @@ PATH remote: . specs: - table_sync (6.5.1) + table_sync (6.6.0) memery - rabbit_messaging (>= 0.13) + rabbit_messaging (>= 1.1.0) rails self_data GEM remote: https://rubygems.org/ specs: - actioncable (7.1.4.1) - actionpack (= 7.1.4.1) - activesupport (= 7.1.4.1) + actioncable (7.1.5.1) + actionpack (= 7.1.5.1) + activesupport (= 7.1.5.1) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (7.1.4.1) - actionpack (= 7.1.4.1) - activejob (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) + actionmailbox (7.1.5.1) + actionpack (= 7.1.5.1) + activejob (= 7.1.5.1) + activerecord (= 7.1.5.1) + activestorage (= 7.1.5.1) + activesupport (= 7.1.5.1) mail (>= 2.7.1) net-imap net-pop net-smtp - actionmailer (7.1.4.1) - actionpack (= 7.1.4.1) - actionview (= 7.1.4.1) - activejob (= 7.1.4.1) - activesupport (= 7.1.4.1) + actionmailer (7.1.5.1) + actionpack (= 7.1.5.1) + actionview (= 7.1.5.1) + activejob (= 7.1.5.1) + activesupport (= 7.1.5.1) mail (~> 2.5, >= 2.5.4) net-imap net-pop net-smtp rails-dom-testing (~> 2.2) - actionpack (7.1.4.1) - actionview (= 7.1.4.1) - activesupport (= 7.1.4.1) + actionpack (7.1.5.1) + actionview (= 7.1.5.1) + activesupport (= 7.1.5.1) nokogiri (>= 1.8.5) racc rack (>= 2.2.4) @@ -46,60 +46,64 @@ GEM rack-test (>= 0.6.3) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - actiontext (7.1.4.1) - actionpack (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) + actiontext (7.1.5.1) + actionpack (= 7.1.5.1) + activerecord (= 7.1.5.1) + activestorage (= 7.1.5.1) + activesupport (= 7.1.5.1) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (7.1.4.1) - activesupport (= 7.1.4.1) + actionview (7.1.5.1) + activesupport (= 7.1.5.1) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (7.1.4.1) - activesupport (= 7.1.4.1) + activejob (7.1.5.1) + activesupport (= 7.1.5.1) globalid (>= 0.3.6) - activemodel (7.1.4.1) - activesupport (= 7.1.4.1) - activerecord (7.1.4.1) - activemodel (= 7.1.4.1) - activesupport (= 7.1.4.1) + activemodel (7.1.5.1) + activesupport (= 7.1.5.1) + activerecord (7.1.5.1) + activemodel (= 7.1.5.1) + activesupport (= 7.1.5.1) timeout (>= 0.4.0) - activestorage (7.1.4.1) - actionpack (= 7.1.4.1) - activejob (= 7.1.4.1) - activerecord (= 7.1.4.1) - activesupport (= 7.1.4.1) + activestorage (7.1.5.1) + actionpack (= 7.1.5.1) + activejob (= 7.1.5.1) + activerecord (= 7.1.5.1) + activesupport (= 7.1.5.1) marcel (~> 1.0) - activesupport (7.1.4.1) + activesupport (7.1.5.1) base64 + benchmark (>= 0.3) bigdecimal concurrent-ruby (~> 1.0, >= 1.0.2) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + logger (>= 1.4.2) minitest (>= 5.1) mutex_m + securerandom (>= 0.3) tzinfo (~> 2.0) amq-protocol (2.3.2) ast (2.4.2) base64 (0.2.0) + benchmark (0.4.0) bigdecimal (3.1.8) builder (3.3.0) bundler-audit (0.9.1) bundler (>= 1.2.0, < 3) thor (~> 1.0) - bunny (2.22.0) + bunny (2.23.0) amq-protocol (~> 2.3, >= 2.3.1) sorted_set (~> 1, >= 1.0.2) coderay (1.1.3) concurrent-ruby (1.3.4) connection_pool (2.4.1) crass (1.0.6) - date (3.3.4) + date (3.4.1) diff-lcs (1.5.0) docile (1.4.0) drb (2.2.1) @@ -108,14 +112,21 @@ GEM activesupport (>= 6.1) i18n (1.14.6) concurrent-ruby (~> 1.0) - io-console (0.7.2) - irb (1.14.1) + io-console (0.8.0) + irb (1.14.2) rdoc (>= 4.0.0) reline (>= 0.4.2) json (2.6.3) - lamian (1.7.0) + kicks (3.1.1) + bunny (~> 2.19) + concurrent-ruby (~> 1.0) + rake (>= 12.3, < 14.0) + serverengine (~> 2.1) + thor + lamian (1.10.0) rails (>= 4.2) - loofah (2.22.0) + logger (1.6.3) + loofah (2.23.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -128,10 +139,10 @@ GEM ruby2_keywords (~> 0.0.2) method_source (1.1.0) mini_mime (1.1.5) - mini_portile2 (2.8.7) - minitest (5.25.1) - mutex_m (0.2.0) - net-imap (0.4.17) + mini_portile2 (2.8.8) + minitest (5.25.4) + mutex_m (0.3.0) + net-imap (0.5.2) date net-protocol net-pop (0.1.2) @@ -140,8 +151,8 @@ GEM timeout net-smtp (0.5.0) net-protocol - nio4r (2.7.3) - nokogiri (1.16.7) + nio4r (2.7.4) + nokogiri (1.17.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) parallel (1.23.0) @@ -152,13 +163,14 @@ GEM pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - psych (5.1.2) + psych (5.2.1) + date stringio - rabbit_messaging (0.13.0) + rabbit_messaging (1.1.0) bunny (~> 2.0) + kicks (~> 3) lamian - rails (>= 5.2) - sneakers (~> 2.0) + rails (>= 6.1) tainbox racc (1.8.1) rack (3.1.8) @@ -166,33 +178,32 @@ GEM rack (>= 3.0.0) rack-test (2.1.0) rack (>= 1.3) - rackup (2.1.0) + rackup (2.2.1) rack (>= 3) - webrick (~> 1.8) - rails (7.1.4.1) - actioncable (= 7.1.4.1) - actionmailbox (= 7.1.4.1) - actionmailer (= 7.1.4.1) - actionpack (= 7.1.4.1) - actiontext (= 7.1.4.1) - actionview (= 7.1.4.1) - activejob (= 7.1.4.1) - activemodel (= 7.1.4.1) - activerecord (= 7.1.4.1) - activestorage (= 7.1.4.1) - activesupport (= 7.1.4.1) + rails (7.1.5.1) + actioncable (= 7.1.5.1) + actionmailbox (= 7.1.5.1) + actionmailer (= 7.1.5.1) + actionpack (= 7.1.5.1) + actiontext (= 7.1.5.1) + actionview (= 7.1.5.1) + activejob (= 7.1.5.1) + activemodel (= 7.1.5.1) + activerecord (= 7.1.5.1) + activestorage (= 7.1.5.1) + activesupport (= 7.1.5.1) bundler (>= 1.15.0) - railties (= 7.1.4.1) + railties (= 7.1.5.1) rails-dom-testing (2.2.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.0) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) - nokogiri (~> 1.14) - railties (7.1.4.1) - actionpack (= 7.1.4.1) - activesupport (= 7.1.4.1) + nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) + railties (7.1.5.1) + actionpack (= 7.1.5.1) + activesupport (= 7.1.5.1) irb rackup (>= 1.0.0) rake (>= 12.2) @@ -201,12 +212,12 @@ GEM rainbow (3.1.1) rake (13.2.1) rbtree (0.4.6) - rdoc (6.7.0) + rdoc (6.9.1) psych (>= 4.0.0) regexp_parser (2.8.1) - reline (0.5.10) + reline (0.6.0) io-console (~> 0.5) - rexml (3.3.8) + rexml (3.3.9) rspec (3.12.0) rspec-core (~> 3.12.0) rspec-expectations (~> 3.12.0) @@ -257,11 +268,14 @@ GEM rubocop (~> 1.0) ruby-progressbar (1.13.0) ruby2_keywords (0.0.5) + securerandom (0.4.1) self_data (1.3.0) sequel (5.71.0) - serverengine (2.0.7) + serverengine (2.4.0) + base64 (~> 0.1) + logger (~> 1.4) sigdump (~> 0.2.2) - set (1.0.3) + set (1.1.1) sigdump (0.2.5) simplecov (0.22.0) docile (~> 1.1) @@ -270,25 +284,18 @@ GEM simplecov-html (0.12.3) simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.4) - sneakers (2.11.0) - bunny (~> 2.12) - concurrent-ruby (~> 1.0) - rake - serverengine (~> 2.0.5) - thor sorted_set (1.0.3) rbtree set (~> 1.0) - stringio (3.1.1) + stringio (3.1.2) tainbox (2.1.2) activesupport thor (1.3.2) timecop (0.9.7) - timeout (0.4.1) + timeout (0.4.3) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.4.2) - webrick (1.8.2) websocket-driver (0.7.6) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) diff --git a/lib/table_sync.rb b/lib/table_sync.rb index dfabd9f..0ac8aec 100644 --- a/lib/table_sync.rb +++ b/lib/table_sync.rb @@ -47,7 +47,7 @@ class << self def sync(object_class, **options) setup.new( - object_class: object_class, + object_class:, on: options[:on], if_condition: options[:if], unless_condition: options[:unless], diff --git a/lib/table_sync/instrument_adapter/active_support.rb b/lib/table_sync/instrument_adapter/active_support.rb index 7b37a4b..8d60a34 100644 --- a/lib/table_sync/instrument_adapter/active_support.rb +++ b/lib/table_sync/instrument_adapter/active_support.rb @@ -6,11 +6,11 @@ module ActiveSupport def notify(table:, schema:, event:, direction:, count: 1) ::ActiveSupport::Notifications.instrument "tablesync.#{direction}.#{event}", - count: count, + count:, table: table.to_s, schema: schema.to_s, - event: event, - direction: direction + event:, + direction: end end end diff --git a/lib/table_sync/publishing/batch.rb b/lib/table_sync/publishing/batch.rb index 2364407..cb81bf4 100644 --- a/lib/table_sync/publishing/batch.rb +++ b/lib/table_sync/publishing/batch.rb @@ -6,7 +6,7 @@ class TableSync::Publishing::Batch attribute :object_class attribute :original_attributes - + attribute :custom_version attribute :routing_key attribute :headers diff --git a/lib/table_sync/publishing/data/objects.rb b/lib/table_sync/publishing/data/objects.rb index f1ab5e3..7cda0a5 100644 --- a/lib/table_sync/publishing/data/objects.rb +++ b/lib/table_sync/publishing/data/objects.rb @@ -2,18 +2,19 @@ module TableSync::Publishing::Data class Objects - attr_reader :objects, :event + attr_reader :objects, :event, :custom_version - def initialize(objects:, event:) - @objects = objects - @event = TableSync::Event.new(event) + def initialize(objects:, event:, custom_version:) + @objects = objects + @event = TableSync::Event.new(event) + @custom_version = custom_version end def construct { - model: model, + model:, attributes: attributes_for_sync, - version: version, + version: custom_version || version, event: event.resolve, metadata: event.metadata, } diff --git a/lib/table_sync/publishing/data/raw.rb b/lib/table_sync/publishing/data/raw.rb index f5fffdd..c5d70d4 100644 --- a/lib/table_sync/publishing/data/raw.rb +++ b/lib/table_sync/publishing/data/raw.rb @@ -2,19 +2,20 @@ module TableSync::Publishing::Data class Raw - attr_reader :model_name, :attributes_for_sync, :event + attr_reader :model_name, :attributes_for_sync, :event, :custom_version - def initialize(model_name:, attributes_for_sync:, event:) + def initialize(model_name:, attributes_for_sync:, event:, custom_version:) @model_name = model_name @attributes_for_sync = attributes_for_sync @event = TableSync::Event.new(event) + @custom_version = custom_version end def construct { model: model_name, attributes: wrapped_attributes_for_sync, - version: version, + version: custom_version || version, event: event.resolve, metadata: event.metadata, } diff --git a/lib/table_sync/publishing/message/base.rb b/lib/table_sync/publishing/message/base.rb index a2af8bc..49940f5 100644 --- a/lib/table_sync/publishing/message/base.rb +++ b/lib/table_sync/publishing/message/base.rb @@ -6,6 +6,7 @@ class Base attr_reader :objects + attribute :custom_version attribute :object_class attribute :original_attributes attribute :event @@ -32,19 +33,21 @@ def empty? def find_or_init_objects TableSync::Publishing::Helpers::Objects.new( - object_class: object_class, original_attributes: original_attributes, event: event, + object_class:, original_attributes:, event:, ).construct_list end # MESSAGE PARAMS def message_params - params.merge(data: data) + params.merge(data:) end def data TableSync::Publishing::Data::Objects.new( - objects: objects, event: event, + objects:, + event:, + custom_version:, ).construct end @@ -60,7 +63,7 @@ def notify! TableSync::Instrument.notify( table: model_naming.table, schema: model_naming.schema, - event: event, + event:, direction: :publish, count: objects.count, ) diff --git a/lib/table_sync/publishing/message/raw.rb b/lib/table_sync/publishing/message/raw.rb index 661d624..a7a1a79 100644 --- a/lib/table_sync/publishing/message/raw.rb +++ b/lib/table_sync/publishing/message/raw.rb @@ -11,7 +11,7 @@ class Raw attribute :routing_key attribute :headers - + attribute :custom_version attribute :event def publish @@ -26,7 +26,7 @@ def notify! TableSync::Instrument.notify( table: table_name, schema: schema_name, - event: event, + event:, count: original_attributes.count, direction: :publish, ) @@ -35,12 +35,15 @@ def notify! # MESSAGE PARAMS def message_params - params.merge(data: data) + params.merge(data:) end def data TableSync::Publishing::Data::Raw.new( - model_name: model_name, attributes_for_sync: original_attributes, event: event, + model_name:, + attributes_for_sync: original_attributes, + event:, + custom_version:, ).construct end diff --git a/lib/table_sync/publishing/message/single.rb b/lib/table_sync/publishing/message/single.rb index 3b02d53..40ae8ab 100644 --- a/lib/table_sync/publishing/message/single.rb +++ b/lib/table_sync/publishing/message/single.rb @@ -7,7 +7,7 @@ def object end def params - TableSync::Publishing::Params::Single.new(object: object).construct + TableSync::Publishing::Params::Single.new(object:).construct end end end diff --git a/lib/table_sync/publishing/params/base.rb b/lib/table_sync/publishing/params/base.rb index 178642f..a8ca63a 100644 --- a/lib/table_sync/publishing/params/base.rb +++ b/lib/table_sync/publishing/params/base.rb @@ -10,9 +10,9 @@ class Base def construct DEFAULT_PARAMS.merge( - routing_key: routing_key, - headers: headers, - exchange_name: exchange_name, + routing_key:, + headers:, + exchange_name:, ) end diff --git a/lib/table_sync/publishing/raw.rb b/lib/table_sync/publishing/raw.rb index 7c0f2e1..16f1a9c 100644 --- a/lib/table_sync/publishing/raw.rb +++ b/lib/table_sync/publishing/raw.rb @@ -8,13 +8,13 @@ class TableSync::Publishing::Raw attribute :table_name attribute :schema_name attribute :original_attributes - + attribute :custom_version attribute :routing_key attribute :headers attribute :event, default: :update - require_attributes :model_name, :original_attributes + require_attributes :model_name, :original_attributes, :table_name, :schema_name def publish_now message.publish diff --git a/lib/table_sync/publishing/single.rb b/lib/table_sync/publishing/single.rb index 063b6fa..81f6a6e 100644 --- a/lib/table_sync/publishing/single.rb +++ b/lib/table_sync/publishing/single.rb @@ -7,7 +7,7 @@ class TableSync::Publishing::Single attribute :object_class attribute :original_attributes attribute :debounce_time - + attribute :custom_version attribute :event, Symbol, default: :update # expect job to have perform_at method @@ -31,10 +31,10 @@ def publish_now memoize def debounce TableSync::Publishing::Helpers::Debounce.new( - object_class: object_class, + object_class:, needle: message.object.needle, - debounce_time: debounce_time, - event: event, + debounce_time:, + event:, ) end diff --git a/lib/table_sync/receiving/config_decorator.rb b/lib/table_sync/receiving/config_decorator.rb index 477603b..a851263 100644 --- a/lib/table_sync/receiving/config_decorator.rb +++ b/lib/table_sync/receiving/config_decorator.rb @@ -10,18 +10,18 @@ def initialize(config:, event:, model:, version:, project_id:, raw_data:) @config = config @default_params = { - event: event, - model: model, - version: version, - project_id: project_id, - raw_data: raw_data, + event:, + model:, + version:, + project_id:, + raw_data:, } end # rubocop:enable Metrics/ParameterLists - def method_missing(name, **additional_params, &block) + def method_missing(name, **additional_params, &) value = @config.send(name) - value.is_a?(Proc) ? value.call(@default_params.merge(additional_params), &block) : value + value.is_a?(Proc) ? value.call(@default_params.merge(additional_params), &) : value end end end diff --git a/lib/table_sync/receiving/dsl.rb b/lib/table_sync/receiving/dsl.rb index 482eb16..539fe66 100644 --- a/lib/table_sync/receiving/dsl.rb +++ b/lib/table_sync/receiving/dsl.rb @@ -16,7 +16,7 @@ def receive(source, to_table: nil, to_model: nil, events: [:update, :destroy], & TableSync::Utils::InterfaceChecker.new(model).implements(:receiving_model) - config = ::TableSync::Receiving::Config.new(model: model, events: events) + config = ::TableSync::Receiving::Config.new(model:, events:) config.instance_exec(&block) if block diff --git a/lib/table_sync/receiving/handler.rb b/lib/table_sync/receiving/handler.rb index 29d5c0b..cc7994e 100644 --- a/lib/table_sync/receiving/handler.rb +++ b/lib/table_sync/receiving/handler.rb @@ -16,22 +16,22 @@ def call next if data.empty? - version_key = config.version_key(data: data) + version_key = config.version_key(data:) data.each { |row| row[version_key] = version } - target_keys = config.target_keys(data: data) + target_keys = config.target_keys(data:) - validate_data(data, target_keys: target_keys) + validate_data(data, target_keys:) data.sort_by! { |row| row.values_at(*target_keys).map { |value| sort_key(value) } } - params = { data: data, target_keys: target_keys, version_key: version_key } + params = { data:, target_keys:, version_key: } if event == :update - params[:default_values] = config.default_values(data: data) + params[:default_values] = config.default_values(data:) end - config.wrap_receiving(event: event, **params) do + config.wrap_receiving(event:, **params) do perform(config, params) end end @@ -64,12 +64,12 @@ def configs configs = configs.sort_by { |config| "#{config.model.schema}.#{config.model.table}" } configs.map do |config| ::TableSync::Receiving::ConfigDecorator.new( - config: config, + config:, # next parameters will be send to each proc-options from config - event: event, - model: model, - version: version, - project_id: project_id, + event:, + model:, + version:, + project_id:, raw_data: data, ) end @@ -78,22 +78,22 @@ def configs def processed_data(config) data.filter_map do |row| - next if config.skip(row: row) + next if config.skip(row:) row = row.dup - config.mapping_overrides(row: row).each do |before, after| + config.mapping_overrides(row:).each do |before, after| row[after] = row.delete(before) end - config.except(row: row).each { |x| row.delete(x) } + config.except(row:).each { |x| row.delete(x) } - row.merge!(config.additional_data(row: row)) + row.merge!(config.additional_data(row:)) - only = config.only(row: row) + only = config.only(row:) row, rest = row.partition { |key, _| key.in?(only) }.map(&:to_h) - rest_key = config.rest_key(row: row, rest: rest) + rest_key = config.rest_key(row:, rest:) (row[rest_key] ||= {}).merge!(rest) if rest_key row @@ -139,13 +139,13 @@ def perform(config, params) model.after_commit do TableSync::Instrument.notify table: model.table, schema: model.schema, - count: results.count, event: event, direction: :receive + count: results.count, event:, direction: :receive end if event == :update - model.after_commit { config.after_commit_on_update(**params.merge(results: results)) } + model.after_commit { config.after_commit_on_update(**params.merge(results:)) } else - model.after_commit { config.after_commit_on_destroy(**params.merge(results: results)) } + model.after_commit { config.after_commit_on_destroy(**params.merge(results:)) } end end end diff --git a/lib/table_sync/receiving/model/active_record.rb b/lib/table_sync/receiving/model/active_record.rb index bd02d05..73fa8ac 100644 --- a/lib/table_sync/receiving/model/active_record.rb +++ b/lib/table_sync/receiving/model/active_record.rb @@ -26,7 +26,7 @@ def initialize(table_name) self.inheritance_column = nil end - model_naming = ::TableSync::NamingResolver::ActiveRecord.new(table_name: table_name) + model_naming = ::TableSync::NamingResolver::ActiveRecord.new(table_name:) @table = model_naming.table.to_sym @schema = model_naming.schema.to_sym @@ -66,7 +66,7 @@ def upsert(data:, target_keys:, version_key:, default_values:) row = raw_model.lock("FOR NO KEY UPDATE").where(conditions) if row.to_a.size > 1 - raise TableSync::UpsertError.new(data: datum, target_keys: target_keys, result: row) + raise TableSync::UpsertError.new(data: datum, target_keys:, result: row) end row = row.first @@ -99,18 +99,18 @@ def destroy(data:, target_keys:, version_key:) result = query.destroy_all.map { |x| row_to_hash(x) } if result.size > data.size - raise TableSync::DestroyError.new(data: data, target_keys: target_keys, result: result) + raise TableSync::DestroyError.new(data:, target_keys:, result:) end result end - def transaction(&block) - ::ActiveRecord::Base.transaction(&block) + def transaction(&) + ::ActiveRecord::Base.transaction(&) end - def after_commit(&block) - db.add_transaction_record(AfterCommitWrap.new(&block)) + def after_commit(&) + db.add_transaction_record(AfterCommitWrap.new(&)) end private diff --git a/lib/table_sync/receiving/model/sequel.rb b/lib/table_sync/receiving/model/sequel.rb index 7a36f63..a9687d3 100644 --- a/lib/table_sync/receiving/model/sequel.rb +++ b/lib/table_sync/receiving/model/sequel.rb @@ -8,7 +8,7 @@ def initialize(table_name) @raw_model = Class.new(::Sequel::Model(table_name)).tap(&:unrestrict_primary_key) model_naming = ::TableSync::NamingResolver::Sequel.new( - table_name: table_name, + table_name:, db: @raw_model.db, ) @@ -46,18 +46,18 @@ def destroy(data:, target_keys:, version_key:) result = dataset.returning.where(::Sequel.|(*sanitized_data)).delete if result.size > data.size - raise TableSync::DestroyError.new(data: data, target_keys: target_keys, result: result) + raise TableSync::DestroyError.new(data:, target_keys:, result:) end result end - def transaction(&block) - db.transaction(&block) + def transaction(&) + db.transaction(&) end - def after_commit(&block) - db.after_commit(&block) + def after_commit(&) + db.after_commit(&) end private diff --git a/lib/table_sync/setup/active_record.rb b/lib/table_sync/setup/active_record.rb index bb0280c..531f3b7 100644 --- a/lib/table_sync/setup/active_record.rb +++ b/lib/table_sync/setup/active_record.rb @@ -14,7 +14,7 @@ def define_after_commit(event) TableSync::Publishing::Single.new( object_class: self.class.name, original_attributes: attributes, - event: event, + event:, debounce_time: options[:debounce_time], ).publish_later end diff --git a/lib/table_sync/setup/base.rb b/lib/table_sync/setup/base.rb index 0df523f..a2fa9f5 100644 --- a/lib/table_sync/setup/base.rb +++ b/lib/table_sync/setup/base.rb @@ -60,7 +60,7 @@ def options_exposed_for_block { if: if_condition, unless: unless_condition, - debounce_time: debounce_time, + debounce_time:, } end end diff --git a/lib/table_sync/setup/sequel.rb b/lib/table_sync/setup/sequel.rb index 803851f..77d5ceb 100644 --- a/lib/table_sync/setup/sequel.rb +++ b/lib/table_sync/setup/sequel.rb @@ -13,7 +13,7 @@ def define_after_commit(event) TableSync::Publishing::Single.new( object_class: self.class.name, original_attributes: values, - event: event, + event:, debounce_time: options[:debounce_time], ).publish_later end diff --git a/lib/table_sync/utils/proc_array.rb b/lib/table_sync/utils/proc_array.rb index 4898b90..632b2f2 100644 --- a/lib/table_sync/utils/proc_array.rb +++ b/lib/table_sync/utils/proc_array.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true class TableSync::Utils::ProcArray < Proc - def initialize(&block) + def initialize(&) @array = [] - super(&block) + super(&) end def push(&block) @@ -11,7 +11,7 @@ def push(&block) self end - def call(*args, &block) - super(@array, args, &block) + def call(*args, &) + super(@array, args, &) end end diff --git a/lib/table_sync/version.rb b/lib/table_sync/version.rb index 6000ba4..b854062 100644 --- a/lib/table_sync/version.rb +++ b/lib/table_sync/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module TableSync - VERSION = "6.5.1" + VERSION = "6.6.0" end diff --git a/spec/instrument/publish_spec.rb b/spec/instrument/publish_spec.rb index f034233..77d25ca 100644 --- a/spec/instrument/publish_spec.rb +++ b/spec/instrument/publish_spec.rb @@ -39,7 +39,7 @@ def db; end allow(TableSync).to receive(:routing_key_callable) { proc { "routing_key_callable" } } end - let(:player) { double("player", values: attributes, attributes: attributes) } + let(:player) { double("player", values: attributes, attributes:) } let(:events) { [] } let(:event) { events.first } let(:attributes) { { "external_id" => 101, "email" => "email@example.com" } } @@ -47,7 +47,7 @@ def db; end let(:publisher) do publisher_class.new( object_class: "Player", - original_attributes: original_attributes, + original_attributes:, event: :update, ) end diff --git a/spec/publishing/batch_spec.rb b/spec/publishing/batch_spec.rb index 3380c82..3f55e59 100644 --- a/spec/publishing/batch_spec.rb +++ b/spec/publishing/batch_spec.rb @@ -14,11 +14,12 @@ let(:attributes) do { - object_class: object_class, - original_attributes: original_attributes, - event: event, - headers: headers, - routing_key: routing_key, + object_class:, + original_attributes:, + event:, + headers:, + routing_key:, + custom_version: nil, } end diff --git a/spec/publishing/data/objects_spec.rb b/spec/publishing/data/objects_spec.rb index 45cfb09..5afe202 100644 --- a/spec/publishing/data/objects_spec.rb +++ b/spec/publishing/data/objects_spec.rb @@ -13,8 +13,9 @@ let(:params) do { - objects: objects, - event: event, + objects:, + event:, + custom_version: nil, } end @@ -30,7 +31,7 @@ attributes: [expected_attributes], version: an_instance_of(Float), event: resolved_event, - metadata: metadata, + metadata:, } end diff --git a/spec/publishing/data/raw_spec.rb b/spec/publishing/data/raw_spec.rb index e8c1b61..bde7da7 100644 --- a/spec/publishing/data/raw_spec.rb +++ b/spec/publishing/data/raw_spec.rb @@ -9,9 +9,10 @@ let(:params) do { - model_name: model_name, - attributes_for_sync: attributes_for_sync, - event: event, + model_name:, + attributes_for_sync:, + event:, + custom_version: nil, } end @@ -21,7 +22,7 @@ attributes: attributes_for_sync, version: an_instance_of(Float), event: resolved_event, - metadata: metadata, + metadata:, } end diff --git a/spec/publishing/helpers/debounce_spec.rb b/spec/publishing/helpers/debounce_spec.rb index 82a3bfc..6dc16cf 100644 --- a/spec/publishing/helpers/debounce_spec.rb +++ b/spec/publishing/helpers/debounce_spec.rb @@ -5,8 +5,8 @@ { object_class: "SequelUser", needle: { id: 1 }, - debounce_time: debounce_time, - event: event, + debounce_time:, + event:, } end diff --git a/spec/publishing/helpers/objects_spec.rb b/spec/publishing/helpers/objects_spec.rb index 362a36f..b681026 100644 --- a/spec/publishing/helpers/objects_spec.rb +++ b/spec/publishing/helpers/objects_spec.rb @@ -9,8 +9,8 @@ let(:params) do { object_class: "SequelUser", - original_attributes: original_attributes, - event: event, + original_attributes:, + event:, } end diff --git a/spec/publishing/message/batch_spec.rb b/spec/publishing/message/batch_spec.rb index bdc6afb..4fe309c 100644 --- a/spec/publishing/message/batch_spec.rb +++ b/spec/publishing/message/batch_spec.rb @@ -6,11 +6,11 @@ let(:attributes) do { - object_class: object_class, + object_class:, original_attributes: [{ id: 1 }], routing_key: "users", headers: { kek: 1 }, - event: event, + event:, } end @@ -31,6 +31,7 @@ { objects: collection_of_objects, event: attributes[:event], + custom_version: nil, } end diff --git a/spec/publishing/message/raw_spec.rb b/spec/publishing/message/raw_spec.rb index 5ea619b..2bcbd36 100644 --- a/spec/publishing/message/raw_spec.rb +++ b/spec/publishing/message/raw_spec.rb @@ -9,6 +9,7 @@ routing_key: "users", headers: { kek: 1 }, event: :update, + custom_version: nil, } end @@ -24,6 +25,7 @@ model_name: attributes[:model_name], attributes_for_sync: attributes[:original_attributes], event: attributes[:event], + custom_version: attributes[:custom_version], } end diff --git a/spec/publishing/message/single_spec.rb b/spec/publishing/message/single_spec.rb index ae87d1e..bb20941 100644 --- a/spec/publishing/message/single_spec.rb +++ b/spec/publishing/message/single_spec.rb @@ -8,11 +8,12 @@ let(:attributes) do { - object_class: object_class, + object_class:, original_attributes: [{ id: 1 }], routing_key: "users", headers: { kek: 1 }, - event: event, + event:, + custom_version: nil, } end @@ -33,12 +34,13 @@ { objects: collection_of_objects, event: attributes[:event], + custom_version: attributes[:custom_version], } end let(:params_attributes) do { - object: object, + object:, } end diff --git a/spec/publishing/params/batch_spec.rb b/spec/publishing/params/batch_spec.rb index 661a212..bbb3382 100644 --- a/spec/publishing/params/batch_spec.rb +++ b/spec/publishing/params/batch_spec.rb @@ -3,7 +3,7 @@ describe TableSync::Publishing::Params::Batch do let(:object_class) { "User" } let(:attributes) { default_attributes } - let(:default_attributes) { { object_class: object_class } } + let(:default_attributes) { { object_class: } } let(:service) { described_class.new(attributes) } let(:default_expected_values) do @@ -36,19 +36,19 @@ context "headers" do context "from attributes" do let(:headers) { { custom: "kek" } } - let(:attributes) { default_attributes.merge(headers: headers) } - let(:expected_values) { default_expected_values.merge(headers: headers) } + let(:attributes) { default_attributes.merge(headers:) } + let(:expected_values) { default_expected_values.merge(headers:) } include_examples "constructs with expected values" end context "calculated" do let(:expected_values) do - default_expected_values.merge(headers: { object_class: object_class }) + default_expected_values.merge(headers: { object_class: }) end before do - TableSync.headers_callable = -> (object_class, _atrs) { { object_class: object_class } } + TableSync.headers_callable = -> (object_class, _atrs) { { object_class: } } end include_examples "constructs with expected values" @@ -64,8 +64,8 @@ context "routing_key" do context "from attributes" do let(:routing_key) { "custom_routing_key" } - let(:attributes) { default_attributes.merge(routing_key: routing_key) } - let(:expected_values) { default_expected_values.merge(routing_key: routing_key) } + let(:attributes) { default_attributes.merge(routing_key:) } + let(:expected_values) { default_expected_values.merge(routing_key:) } include_examples "constructs with expected values" end @@ -92,15 +92,15 @@ context "exchange_name" do context "from attributes" do let(:exchange_name) { "custom_exchange_name" } - let(:attributes) { default_attributes.merge(exchange_name: exchange_name) } - let(:expected_values) { default_expected_values.merge(exchange_name: exchange_name) } + let(:attributes) { default_attributes.merge(exchange_name:) } + let(:expected_values) { default_expected_values.merge(exchange_name:) } include_examples "constructs with expected values" end context "by default" do let(:exchange_name) { "some.project.table_sync" } - let(:expected_values) { default_expected_values.merge(exchange_name: exchange_name) } + let(:expected_values) { default_expected_values.merge(exchange_name:) } before { TableSync.exchange_name = exchange_name } diff --git a/spec/publishing/params/raw_spec.rb b/spec/publishing/params/raw_spec.rb index 7475c32..b4e3d90 100644 --- a/spec/publishing/params/raw_spec.rb +++ b/spec/publishing/params/raw_spec.rb @@ -36,19 +36,19 @@ context "headers" do context "from attributes" do let(:headers) { { custom: "kek" } } - let(:attributes) { default_attributes.merge(headers: headers) } - let(:expected_values) { default_expected_values.merge(headers: headers) } + let(:attributes) { default_attributes.merge(headers:) } + let(:expected_values) { default_expected_values.merge(headers:) } include_examples "constructs with expected values" end context "calculated" do let(:expected_values) do - default_expected_values.merge(headers: { object_class: object_class }) + default_expected_values.merge(headers: { object_class: }) end before do - TableSync.headers_callable = -> (object_class, _atrs) { { object_class: object_class } } + TableSync.headers_callable = -> (object_class, _atrs) { { object_class: } } end include_examples "constructs with expected values" @@ -64,8 +64,8 @@ context "routing_key" do context "from attributes" do let(:routing_key) { "custom_routing_key" } - let(:attributes) { default_attributes.merge(routing_key: routing_key) } - let(:expected_values) { default_expected_values.merge(routing_key: routing_key) } + let(:attributes) { default_attributes.merge(routing_key:) } + let(:expected_values) { default_expected_values.merge(routing_key:) } include_examples "constructs with expected values" end @@ -92,15 +92,15 @@ context "exchange_name" do context "from attributes" do let(:exchange_name) { "custom_exchange_name" } - let(:attributes) { default_attributes.merge(exchange_name: exchange_name) } - let(:expected_values) { default_expected_values.merge(exchange_name: exchange_name) } + let(:attributes) { default_attributes.merge(exchange_name:) } + let(:expected_values) { default_expected_values.merge(exchange_name:) } include_examples "constructs with expected values" end context "by default" do let(:exchange_name) { "some.project.table_sync" } - let(:expected_values) { default_expected_values.merge(exchange_name: exchange_name) } + let(:expected_values) { default_expected_values.merge(exchange_name:) } before { TableSync.exchange_name = exchange_name } diff --git a/spec/publishing/params/single_spec.rb b/spec/publishing/params/single_spec.rb index 8f4387e..72f66f9 100644 --- a/spec/publishing/params/single_spec.rb +++ b/spec/publishing/params/single_spec.rb @@ -3,12 +3,12 @@ describe TableSync::Publishing::Params::Single do let(:object_class) { "ARecordUser" } let(:attributes) { default_attributes } - let(:default_attributes) { { object: object } } + let(:default_attributes) { { object: } } let(:service) { described_class.new(**attributes) } let(:object) do TableSync::Publishing::Helpers::Objects.new( - object_class: object_class, original_attributes: { id: 1 }, event: :update, + object_class:, original_attributes: { id: 1 }, event: :update, ).construct_list.first end @@ -48,11 +48,11 @@ context "headers" do context "calculated" do let(:expected_values) do - default_expected_values.merge(headers: { object_class: object_class }) + default_expected_values.merge(headers: { object_class: }) end before do - TableSync.headers_callable = -> (object_class, _atrs) { { object_class: object_class } } + TableSync.headers_callable = -> (object_class, _atrs) { { object_class: } } end include_examples "constructs with expected values" @@ -134,7 +134,7 @@ context "exchange_name" do context "by default" do let(:exchange_name) { "some.project.table_sync" } - let(:expected_values) { default_expected_values.merge(exchange_name: exchange_name) } + let(:expected_values) { default_expected_values.merge(exchange_name:) } before { TableSync.exchange_name = exchange_name } diff --git a/spec/publishing/raw_spec.rb b/spec/publishing/raw_spec.rb index 5093c09..4f3b5c1 100644 --- a/spec/publishing/raw_spec.rb +++ b/spec/publishing/raw_spec.rb @@ -8,16 +8,19 @@ let(:expected_routing_key) { "custom_routing_key" } let(:headers) { { some_key: "123" } } let(:original_attributes) { [{ id: 1, name: "purum" }] } + let(:table_name) { "sequel_users" } + let(:schema_name) { "public" } let(:attributes) do { - model_name: model_name, - original_attributes: original_attributes, - routing_key: routing_key, - headers: headers, - event: event, - table_name: nil, - schema_name: nil, + model_name:, + original_attributes:, + routing_key:, + headers:, + event:, + table_name:, + schema_name:, + custom_version: nil, } end @@ -39,5 +42,5 @@ include_examples "publisher#new without expected fields", TableSync::Publishing::Raw, - %i[model_name original_attributes] + %i[model_name original_attributes table_name schema_name] end diff --git a/spec/publishing/single_spec.rb b/spec/publishing/single_spec.rb index b99897b..37c9eb5 100644 --- a/spec/publishing/single_spec.rb +++ b/spec/publishing/single_spec.rb @@ -14,10 +14,11 @@ let(:attributes) do { - object_class: object_class, - original_attributes: original_attributes, - event: event, - debounce_time: debounce_time, + object_class:, + original_attributes:, + event:, + debounce_time:, + custom_version: nil, } end @@ -80,10 +81,10 @@ it "calls debounce" do expect(TableSync::Publishing::Helpers::Debounce).to receive(:new).with( - object_class: object_class, + object_class:, needle: { id: 1 }, - debounce_time: debounce_time, - event: event, + debounce_time:, + event:, ) described_class.new(attributes).publish_later diff --git a/spec/receiving/config_spec.rb b/spec/receiving/config_spec.rb index 2898460..26bd1e1 100644 --- a/spec/receiving/config_spec.rb +++ b/spec/receiving/config_spec.rb @@ -5,31 +5,31 @@ describe "#allow_event?" do it "sets events like a single value" do - config = described_class.new(model: model, events: :update) + config = described_class.new(model:, events: :update) expect(config.allow_event?(:update)).to be(true) end it "sets events like an array value" do - config = described_class.new(model: model, events: %i[update destroy]) + config = described_class.new(model:, events: %i[update destroy]) expect(config.allow_event?(:update)).to be(true) expect(config.allow_event?(:destroy)).to be(true) end it "returns true for :update and :destroy if events is not set" do - config = described_class.new(model: model) + config = described_class.new(model:) expect(config.allow_event?(:update)).to be(true) expect(config.allow_event?(:destroy)).to be(true) expect(config.allow_event?(:wrong_event)).to be(false) end it "returns false for wrong event" do - config = described_class.new(model: model, events: :update) + config = described_class.new(model:, events: :update) expect(config.allow_event?(:destroy)).to be(false) end end describe "options" do - let(:config) { described_class.new(model: model) } + let(:config) { described_class.new(model:) } describe "#only" do it "returns correct default value" do diff --git a/spec/receiving/dsl_spec.rb b/spec/receiving/dsl_spec.rb index bcfadb3..842a4a8 100644 --- a/spec/receiving/dsl_spec.rb +++ b/spec/receiving/dsl_spec.rb @@ -29,10 +29,10 @@ { custom_attr: project_id } end - after_commit_on_update { |data:| test_proc.call(data: data) } - after_commit_on_update { |project_id:| test_proc.call(project_id: project_id) } + after_commit_on_update { |data:| test_proc.call(data:) } + after_commit_on_update { |project_id:| test_proc.call(project_id:) } - wrap_receiving { |data:, &block| test_proc.call(data: data, block: block) } + wrap_receiving { |data:, &block| test_proc.call(data:, block:) } end expect(handler1.configs.key?("User")).to eq(true) @@ -72,9 +72,9 @@ def upsert(data:, target_keys:, version_key:, default_values:); end def destroy(data:, target_keys:); end - def transaction(&block); end + def transaction(&); end - def after_commit(&block); end + def after_commit(&); end def columns; end diff --git a/spec/receiving/handler_spec.rb b/spec/receiving/handler_spec.rb index 6399b6a..9832142 100644 --- a/spec/receiving/handler_spec.rb +++ b/spec/receiving/handler_spec.rb @@ -74,7 +74,7 @@ def fire_destroy_event only :external_id, :project_id, :email wrap_receiving do |event:, **_rest, &receiving| - cool_wrapper.call(event: event) + cool_wrapper.call(event:) receiving.call end end @@ -382,7 +382,7 @@ def fire_destroy_event let(:model) do Class.new(TableSync.receiving_model) do def destroy(data:, target_keys:, version_key:) - DESTROY_INTERCEPTOR.push(data: data, target_keys: target_keys) + DESTROY_INTERCEPTOR.push(data:, target_keys:) [{ text: "on_destroy_completed" }] # returning value end end.new(:players) diff --git a/spec/support/shared/publishers.rb b/spec/support/shared/publishers.rb index e36c004..e9ebafa 100644 --- a/spec/support/shared/publishers.rb +++ b/spec/support/shared/publishers.rb @@ -35,13 +35,13 @@ a_hash_including( data: a_hash_including( attributes: expected_object_data, - event: event, + event:, metadata: { created: false }, model: object_class, version: an_instance_of(Float), ), routing_key: expected_routing_key, # defined by callable by default - headers: headers, # defined by callable by default + headers:, # defined by callable by default ) end diff --git a/spec/support/shared/publishing.rb b/spec/support/shared/publishing.rb index fe51757..890975a 100644 --- a/spec/support/shared/publishing.rb +++ b/spec/support/shared/publishing.rb @@ -4,7 +4,7 @@ before do (1..quantity).each do |id| DB[:users].insert({ - id: id, + id:, name: "test#{id}", email: "mail#{id}", ext_id: id + 100, diff --git a/spec/support/table_sync_settings.rb b/spec/support/table_sync_settings.rb index 09cc682..6ae37c4 100644 --- a/spec/support/table_sync_settings.rb +++ b/spec/support/table_sync_settings.rb @@ -10,7 +10,7 @@ def setup! TableSync.single_publishing_job_class_callable = -> { SingleTestJob } TableSync.batch_publishing_job_class_callable = -> { BatchTestJob } TableSync.routing_key_callable = -> (klass, _attributes) { klass.tableize } - TableSync.headers_callable = -> (klass, _attributes) { { klass: klass } } + TableSync.headers_callable = -> (klass, _attributes) { { klass: } } TableSync.notifier = nil TableSync.notify = nil end diff --git a/table_sync.gemspec b/table_sync.gemspec index ae68cb4..4674f3c 100644 --- a/table_sync.gemspec +++ b/table_sync.gemspec @@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "table_sync/version" Gem::Specification.new do |spec| - spec.required_ruby_version = ">= 3.0.0" + spec.required_ruby_version = ">= 3.1.0" spec.name = "table_sync" spec.version = TableSync::VERSION @@ -27,7 +27,7 @@ Gem::Specification.new do |spec| end spec.add_runtime_dependency "memery" - spec.add_runtime_dependency "rabbit_messaging", ">= 0.13" + spec.add_runtime_dependency "rabbit_messaging", ">= 1.1.0" spec.add_runtime_dependency "rails" spec.add_runtime_dependency "self_data" end