From 94a234e4c842be31565daf71adf8d3dcb21451d6 Mon Sep 17 00:00:00 2001 From: Erik Rozendaal Date: Wed, 4 Mar 2026 17:12:11 +0100 Subject: [PATCH 1/2] Update rubocop --- .rubocop.yml | 3 +++ lib/sequent/core/active_projectors_event_publisher.rb | 2 +- lib/sequent/core/event_store.rb | 2 +- lib/sequent/core/helpers/unique_keys.rb | 2 +- .../core/persistors/replay_optimized_postgres_persistor.rb | 2 +- lib/sequent/core/projector.rb | 2 +- 6 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 8cf0c86e..c9f7c91c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -342,3 +342,6 @@ Style/CollectionQuerying: Enabled: true Lint/AmbiguousRange: Enabled: true + +Style/OneClassPerFile: + Enabled: false diff --git a/lib/sequent/core/active_projectors_event_publisher.rb b/lib/sequent/core/active_projectors_event_publisher.rb index c64dbb24..1e7c6b57 100644 --- a/lib/sequent/core/active_projectors_event_publisher.rb +++ b/lib/sequent/core/active_projectors_event_publisher.rb @@ -30,7 +30,7 @@ def process_events(event_handlers, ...) def ensure_no_unknown_active_projectors!(event_handlers) registered_projectors = event_handlers - .select { |x| x.is_a?(Projector) } + .grep(Projector) .map { |x| x.class.name } activated_projectors = Projectors.projector_states .values diff --git a/lib/sequent/core/event_store.rb b/lib/sequent/core/event_store.rb index 705c967a..68d6f95d 100644 --- a/lib/sequent/core/event_store.rb +++ b/lib/sequent/core/event_store.rb @@ -267,7 +267,7 @@ def event_streams_enumerator(aggregate_type: nil, group_size: 100) end def update_unique_keys(event_streams) - fail ArgumentError, 'array of stream records expected' unless event_streams.all? { |x| x.is_a?(EventStream) } + fail ArgumentError, 'array of stream records expected' unless event_streams.all?(EventStream) call_procedure(connection, 'update_unique_keys', [event_streams.to_json]) rescue ActiveRecord::RecordNotUnique => e diff --git a/lib/sequent/core/helpers/unique_keys.rb b/lib/sequent/core/helpers/unique_keys.rb index 194a9fe6..76fca1be 100644 --- a/lib/sequent/core/helpers/unique_keys.rb +++ b/lib/sequent/core/helpers/unique_keys.rb @@ -33,7 +33,7 @@ module ClassMethods # ``` def unique_key(scope, *attributes, **kwargs) fail ArgumentError, "'#{scope}' is not a symbol" unless scope.is_a?(Symbol) - fail ArgumentError, 'attributes must be symbols' unless attributes.all? { |attr| attr.is_a?(Symbol) } + fail ArgumentError, 'attributes must be symbols' unless attributes.all?(Symbol) @unique_key_definitions ||= {} diff --git a/lib/sequent/core/persistors/replay_optimized_postgres_persistor.rb b/lib/sequent/core/persistors/replay_optimized_postgres_persistor.rb index 900c71b7..6d2dc1d9 100644 --- a/lib/sequent/core/persistors/replay_optimized_postgres_persistor.rb +++ b/lib/sequent/core/persistors/replay_optimized_postgres_persistor.rb @@ -82,7 +82,7 @@ def hash def struct_cache @struct_cache ||= Hash.new do |hash, record_class| - struct_class = Struct.new(*record_class.column_names.map(&:to_sym), keyword_init: true) do + struct_class = Struct.new(*record_class.column_names.map(&:to_sym)) do include InMemoryStruct end hash[record_class] = struct_class diff --git a/lib/sequent/core/projector.rb b/lib/sequent/core/projector.rb index 473befa5..d48eb2d1 100644 --- a/lib/sequent/core/projector.rb +++ b/lib/sequent/core/projector.rb @@ -28,7 +28,7 @@ def version = projector_version || Sequent.migrations_class&.version || 1 end def self.projectors - Sequent.configuration.event_handlers.select { |x| x.is_a? Migratable }.map(&:class) + Sequent.configuration.event_handlers.grep(Migratable).map(&:class) end def self.included(host_class) From f812479d391128205c9c71001719fac2f202326d Mon Sep 17 00:00:00 2001 From: Erik Rozendaal Date: Wed, 4 Mar 2026 17:12:19 +0100 Subject: [PATCH 2/2] All spec defined projector must indicate managed tables Otherwise run-ordering can cause errors when projectors are automatically detected and are checked for managed tables. --- lib/sequent/core/projector.rb | 2 +- spec/lib/sequent/core/projector_spec.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/sequent/core/projector.rb b/lib/sequent/core/projector.rb index d48eb2d1..b68461aa 100644 --- a/lib/sequent/core/projector.rb +++ b/lib/sequent/core/projector.rb @@ -187,7 +187,7 @@ def ensure_record_class_supported!(record_class) def ensure_valid! if self.class.managed_tables.nil? fail <<~EOS.chomp - A Projector must manage at least one table. Did you forget to add `managed_tables` to #{self.class.name}? + A Projector must manage at least one table. Did you forget to add `managed_tables` to #{self.class}? EOS end end diff --git a/spec/lib/sequent/core/projector_spec.rb b/spec/lib/sequent/core/projector_spec.rb index 658f9697..0591a659 100644 --- a/spec/lib/sequent/core/projector_spec.rb +++ b/spec/lib/sequent/core/projector_spec.rb @@ -39,12 +39,13 @@ class MyOtherProjectorTable context 'versioning' do let(:parent_projector_class) do Class.new(Sequent::Core::Projector) do + manages_no_tables self.version = 3 end end it 'should default to 1 if not specified' do - projector_class = Class.new(Sequent::Core::Projector) + projector_class = Class.new(Sequent::Core::Projector) { manages_no_tables } expect(projector_class.version).to eq(1) end