pg_eventstore 1.13.1 → 1.13.2

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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +126 -0
  3. data/CHANGELOG.md +4 -0
  4. data/exe/pg-eventstore +6 -6
  5. data/lib/pg_eventstore/abstract_command.rb +1 -1
  6. data/lib/pg_eventstore/callbacks.rb +7 -2
  7. data/lib/pg_eventstore/cli/commands/callback_handlers/start_cmd_handlers.rb +1 -0
  8. data/lib/pg_eventstore/cli/commands/start_subscriptions_command.rb +5 -4
  9. data/lib/pg_eventstore/cli/parser_options/metadata.rb +4 -4
  10. data/lib/pg_eventstore/cli/parsers/default_parser.rb +8 -8
  11. data/lib/pg_eventstore/cli/parsers/subscription_parser.rb +2 -2
  12. data/lib/pg_eventstore/cli/try_to_delete_subscriptions_set.rb +4 -1
  13. data/lib/pg_eventstore/cli.rb +4 -4
  14. data/lib/pg_eventstore/commands/all_stream_read_grouped.rb +2 -2
  15. data/lib/pg_eventstore/commands/event_modifiers/prepare_link_event.rb +1 -0
  16. data/lib/pg_eventstore/commands/link_to.rb +4 -5
  17. data/lib/pg_eventstore/commands/multiple.rb +1 -3
  18. data/lib/pg_eventstore/commands/regular_stream_read_paginated.rb +1 -1
  19. data/lib/pg_eventstore/config.rb +1 -1
  20. data/lib/pg_eventstore/connection.rb +4 -1
  21. data/lib/pg_eventstore/errors.rb +3 -1
  22. data/lib/pg_eventstore/extensions/callbacks_extension.rb +2 -0
  23. data/lib/pg_eventstore/extensions/options_extension.rb +10 -10
  24. data/lib/pg_eventstore/extensions/using_connection_extension.rb +1 -1
  25. data/lib/pg_eventstore/pg_connection.rb +7 -5
  26. data/lib/pg_eventstore/queries/event_queries.rb +11 -10
  27. data/lib/pg_eventstore/queries/partition_queries.rb +4 -4
  28. data/lib/pg_eventstore/queries/transaction_queries.rb +5 -9
  29. data/lib/pg_eventstore/query_builders/events_filtering.rb +13 -13
  30. data/lib/pg_eventstore/query_builders/partitions_filtering.rb +6 -8
  31. data/lib/pg_eventstore/rspec/has_option_matcher.rb +12 -13
  32. data/lib/pg_eventstore/rspec/test_helpers.rb +4 -3
  33. data/lib/pg_eventstore/sql_builder.rb +9 -13
  34. data/lib/pg_eventstore/stream.rb +8 -8
  35. data/lib/pg_eventstore/subscriptions/basic_runner.rb +4 -3
  36. data/lib/pg_eventstore/subscriptions/commands_handler.rb +1 -1
  37. data/lib/pg_eventstore/subscriptions/events_processor.rb +1 -1
  38. data/lib/pg_eventstore/subscriptions/extensions/base_command_extension.rb +10 -8
  39. data/lib/pg_eventstore/subscriptions/queries/subscription_command_queries.rb +23 -21
  40. data/lib/pg_eventstore/subscriptions/queries/subscription_queries.rb +11 -8
  41. data/lib/pg_eventstore/subscriptions/queries/subscriptions_set_command_queries.rb +8 -13
  42. data/lib/pg_eventstore/subscriptions/queries/subscriptions_set_queries.rb +7 -6
  43. data/lib/pg_eventstore/subscriptions/runner_recovery_strategies/restore_connection.rb +3 -1
  44. data/lib/pg_eventstore/subscriptions/runner_recovery_strategies/restore_subscription_runner.rb +1 -0
  45. data/lib/pg_eventstore/subscriptions/runner_state.rb +3 -1
  46. data/lib/pg_eventstore/subscriptions/subscription.rb +11 -10
  47. data/lib/pg_eventstore/subscriptions/subscription_handler_performance.rb +1 -1
  48. data/lib/pg_eventstore/subscriptions/subscription_runner.rb +1 -1
  49. data/lib/pg_eventstore/subscriptions/subscriptions_manager.rb +5 -7
  50. data/lib/pg_eventstore/subscriptions/subscriptions_set.rb +8 -8
  51. data/lib/pg_eventstore/subscriptions/subscriptions_set_lifecycle.rb +2 -0
  52. data/lib/pg_eventstore/tasks/setup.rake +7 -6
  53. data/lib/pg_eventstore/utils.rb +8 -4
  54. data/lib/pg_eventstore/version.rb +1 -1
  55. data/lib/pg_eventstore/web/application.rb +22 -15
  56. data/lib/pg_eventstore/web/paginator/event_types_collection.rb +9 -11
  57. data/lib/pg_eventstore/web/paginator/events_collection.rb +6 -7
  58. data/lib/pg_eventstore/web/paginator/helpers.rb +19 -19
  59. data/lib/pg_eventstore/web/paginator/stream_contexts_collection.rb +9 -9
  60. data/lib/pg_eventstore/web/paginator/stream_ids_collection.rb +9 -10
  61. data/lib/pg_eventstore/web/paginator/stream_names_collection.rb +9 -11
  62. data/lib/pg_eventstore/web/subscriptions/set_collection.rb +1 -1
  63. data/lib/pg_eventstore/web/subscriptions/subscriptions_to_set_association.rb +2 -0
  64. data/lib/pg_eventstore/web/subscriptions/with_state/set_collection.rb +1 -1
  65. data/lib/pg_eventstore.rb +3 -11
  66. data/pg_eventstore.gemspec +19 -19
  67. data/sig/pg_eventstore/client.rbs +4 -8
  68. data/sig/pg_eventstore/subscriptions/subscriptions_manager.rbs +2 -0
  69. data/sig/pg_eventstore/web/application.rbs +2 -0
  70. metadata +8 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8ddfb0310abc9f9b78b20c0f8c6466ad2ae585ce66fd7ecae7a94bd6fe179a6
4
- data.tar.gz: 2e06fa6f70db70b61f867d33a02eb8c13b50937f6c5afc7cf29f670f8759a9af
3
+ metadata.gz: 5411bc50e9e33cb1e75d41e3e0955ea68b2f4964a431a039a773727e14575840
4
+ data.tar.gz: cb0d9c313a28ea13be313bd6c7f7760513b85ad3f4a660ab66588ef2fc1a6441
5
5
  SHA512:
6
- metadata.gz: f31f6c07073da1a1f460cf65ec55056e1bc7ab28c72f69361cf2c77219ea529324eba85aebbd94cffecbcf3d0354c73b43ca9c3441a7dae39fbc91df8bce792f
7
- data.tar.gz: 8b60ce11b14e5832d53f732690043c55662d5007a919d7a734199a55b4f07be7f1faa1ee13163dda12cac4e7772d6f7a12d57966a07ea021dd00b6cfee80a549
6
+ metadata.gz: 733b57829ff8883f24dd205b1aeb98ff39c2cf33c522ebcd11e9f1b984ee71844edf8cf907928a2cea729732f569b84b432461e8db264bf6d68e79d1f2b9a27b
7
+ data.tar.gz: fc6bfb9d2acbd4dc8cc3e9f981d5280aecdc3ecd8527a24bf7704309c9b2a52aff08f416e77da2279682ee474ab2c0ecbe014690fcff6969eda7b6199fd404e3
data/.rubocop.yml ADDED
@@ -0,0 +1,126 @@
1
+ plugins:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ TargetRubyVersion: '3.0'
6
+ NewCops: enable
7
+ Exclude:
8
+ - 'benchmark/*'
9
+ - 'dev_scripts/**/*'
10
+
11
+ Layout/LineLength:
12
+ Max: 120
13
+
14
+ Layout/DotPosition:
15
+ EnforcedStyle: 'trailing'
16
+
17
+ Naming/PredicateMethod:
18
+ Enabled: false
19
+
20
+ Style/Documentation:
21
+ Enabled: false
22
+
23
+ RSpec/MultipleMemoizedHelpers:
24
+ Enabled: false
25
+
26
+ RSpec/IndexedLet:
27
+ Enabled: false
28
+
29
+ RSpec/NestedGroups:
30
+ Max: 6
31
+
32
+ RSpec/LetSetup:
33
+ Enabled: false
34
+
35
+ RSpec/MatchArray:
36
+ Enabled: false
37
+
38
+ RSpec/NamedSubject:
39
+ Enabled: false
40
+
41
+ RSpec/EmptyLineAfterExample:
42
+ Enabled: false
43
+
44
+ RSpec/ImplicitSubject:
45
+ Enabled: false
46
+
47
+ RSpec/BeEq:
48
+ Enabled: false
49
+
50
+ RSpec/ExampleLength:
51
+ Enabled: false
52
+
53
+ RSpec/SpecFilePathFormat:
54
+ Enabled: false
55
+
56
+ RSpec/ExpectChange:
57
+ Enabled: false
58
+
59
+ RSpec/VerifiedDoubles:
60
+ Enabled: false
61
+
62
+ RSpec/DescribeClass:
63
+ Enabled: false
64
+
65
+ Metrics:
66
+ Enabled: false
67
+
68
+ Style/TrailingCommaInHashLiteral:
69
+ EnforcedStyleForMultiline: comma
70
+
71
+ Style/TrailingCommaInArrayLiteral:
72
+ EnforcedStyleForMultiline: comma
73
+
74
+ Style/Semicolon:
75
+ Exclude:
76
+ - 'spec/**/*.rb'
77
+
78
+ Style/BlockDelimiters:
79
+ Exclude:
80
+ - 'spec/**/*.rb'
81
+
82
+ Style/RescueStandardError:
83
+ Enabled: false
84
+
85
+ Style/NumericPredicate:
86
+ EnforcedStyle: comparison
87
+
88
+ Style/AccessorGrouping:
89
+ Enabled: false
90
+
91
+ Style/RaiseArgs:
92
+ Enabled: false
93
+
94
+ Style/RescueModifier:
95
+ Exclude:
96
+ - 'spec/**/*.rb'
97
+
98
+ Style/EmptyMethod:
99
+ EnforcedStyle: expanded
100
+
101
+ Style/FetchEnvVar:
102
+ Enabled: false
103
+
104
+ Style/NumberedParameters:
105
+ Exclude:
106
+ - 'spec/**/*.rb'
107
+
108
+ Lint/NoReturnInBeginEndBlocks:
109
+ Enabled: false
110
+
111
+ Naming/RescuedExceptionsVariableName:
112
+ Enabled: false
113
+
114
+ Lint/SuppressedException:
115
+ Exclude:
116
+ - 'spec/**/*.rb'
117
+
118
+ Lint/AmbiguousBlockAssociation:
119
+ Exclude:
120
+ - 'spec/**/*.rb'
121
+
122
+ Gemspec/RequiredRubyVersion:
123
+ Enabled: false
124
+
125
+ Gemspec/RequireMFA:
126
+ Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [1.13.2]
4
+
5
+ - Fix a bug that prevents correct processing of CLI commands using public API
6
+
3
7
  ## [1.13.1]
4
8
 
5
9
  - Do not modify public methods arguments
data/exe/pg-eventstore CHANGED
@@ -1,15 +1,15 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require "pg_eventstore"
5
- require "pg_eventstore/cli"
6
- require "logger"
4
+ require 'pg_eventstore'
5
+ require 'pg_eventstore/cli'
6
+ require 'logger'
7
7
 
8
- logger = Logger.new(STDOUT)
8
+ logger = Logger.new($stdout)
9
9
  logger.level = :info
10
- logger.progname = "pg_eventstore"
10
+ logger.progname = 'pg_eventstore'
11
11
  logger.formatter = proc do |severity, time, progname, msg|
12
- "\e[36m#{progname} | \e[0m#{time.utc.strftime("%FT%TZ")} #{severity}: #{msg}\n"
12
+ "\e[36m#{progname} | \e[0m#{time.utc.strftime('%FT%TZ')} #{severity}: #{msg}\n"
13
13
  end
14
14
 
15
15
  PgEventstore.logger = logger
@@ -14,7 +14,7 @@ module PgEventstore
14
14
  end
15
15
 
16
16
  def call(*, **)
17
- raise NotImplementedError, "Implement #call in your child class."
17
+ raise NotImplementedError, 'Implement #call in your child class.'
18
18
  end
19
19
  end
20
20
  end
@@ -121,11 +121,16 @@ module PgEventstore
121
121
  end
122
122
 
123
123
  # @return [Object] the result of the passed block
124
- def run_around_callbacks(action, *args, **kwargs, &blk)
124
+ def run_around_callbacks(action, *args, **kwargs, &_blk)
125
125
  result = nil
126
126
  stack = [proc { result = yield if block_given? }]
127
127
  @callbacks[action][:around]&.reverse_each&.with_index do |callback, index|
128
- stack.push(proc { callback.call(stack[index], *args, **kwargs); result })
128
+ stack.push(
129
+ proc {
130
+ callback.call(stack[index], *args, **kwargs)
131
+ result
132
+ }
133
+ )
129
134
  end
130
135
  stack.last.call(*args, **kwargs)
131
136
  result
@@ -29,6 +29,7 @@ module PgEventstore
29
29
  TEXT
30
30
  )
31
31
  raise unless TryUnlockSubscriptionsSet.try_unlock(manager.config_name, error.lock_id)
32
+
32
33
  retry
33
34
  end
34
35
  end
@@ -39,7 +39,7 @@ module PgEventstore
39
39
  def running_subscriptions?
40
40
  return true if @subscription_managers.any?(&:running?)
41
41
 
42
- PgEventstore.logger&.warn("No subscriptions start ups were detected. Existing...")
42
+ PgEventstore.logger&.warn('No subscriptions start ups were detected. Existing...')
43
43
  false
44
44
  end
45
45
 
@@ -47,7 +47,7 @@ module PgEventstore
47
47
  def setup_killsig
48
48
  Kernel.trap('TERM') do
49
49
  Thread.new do
50
- PgEventstore.logger&.info("Received TERM signal, stopping subscriptions and exiting...")
50
+ PgEventstore.logger&.info('Received TERM signal, stopping subscriptions and exiting...')
51
51
  end.join
52
52
  # Because the implementation uses Mutex - wrap it into Thread to bypass the limitations of Kernel#trap
53
53
  @subscription_managers.map do |manager|
@@ -69,14 +69,15 @@ module PgEventstore
69
69
 
70
70
  # @return [void]
71
71
  def keep_process_alive
72
- PgEventstore.logger&.info("Startup is successful. Processing subscriptions...")
72
+ PgEventstore.logger&.info('Startup is successful. Processing subscriptions...')
73
73
  loop do
74
74
  # SubscriptionsManager#subscriptions_set becomes nil when everything gets stopped.
75
75
  if @subscription_managers.all? { |manager| manager.subscriptions_set.nil? }
76
- PgEventstore.logger&.info("All subscriptions were gracefully shut down. Exiting now...")
76
+ PgEventstore.logger&.info('All subscriptions were gracefully shut down. Exiting now...')
77
77
  break
78
78
  end
79
79
  break unless @running
80
+
80
81
  sleep KEEP_ALIVE_INTERVAL
81
82
  end
82
83
  end
@@ -21,12 +21,12 @@ module PgEventstore
21
21
  to_parser_opts.hash
22
22
  end
23
23
 
24
- # @param another [Object]
24
+ # @param other [Object]
25
25
  # @return [Boolean]
26
- def ==(another)
27
- return false unless another.is_a?(Metadata)
26
+ def ==(other)
27
+ return false unless other.is_a?(Metadata)
28
28
 
29
- to_parser_opts == another.to_parser_opts
29
+ to_parser_opts == other.to_parser_opts
30
30
  end
31
31
  alias eql? ==
32
32
  end
@@ -8,14 +8,14 @@ module PgEventstore
8
8
  # @return [String]
9
9
  def banner
10
10
  <<~TEXT
11
- Usage: pg-eventstore [options]
12
- pg-eventstore [command]
13
-
14
- Commands:
15
- subscriptions Start, stop subscriptions
16
-
17
- Options:
18
- TEXT
11
+ Usage: pg-eventstore [options]
12
+ pg-eventstore [command]
13
+
14
+ Commands:
15
+ subscriptions Start, stop subscriptions
16
+
17
+ Options:
18
+ TEXT
19
19
  end
20
20
  end
21
21
  end
@@ -9,9 +9,9 @@ module PgEventstore
9
9
  def banner
10
10
  <<~TEXT
11
11
  Usage: pg-eventstore subscriptions [command] [options]
12
-
12
+
13
13
  Commands:
14
- start Start subscriptions. Example: pg-eventstore subscriptions start -r lib/my_subscriptions.rb
14
+ start Start subscriptions. Example: pg-eventstore subscriptions start -r lib/my_subscriptions.rb
15
15
  stop Stop subscriptions. Example: pg-eventstore subscriptions stop
16
16
 
17
17
  Options:
@@ -32,7 +32,10 @@ module PgEventstore
32
32
  # Wait for potential recover plus run interval and plus another second to allow potential processing of
33
33
  # "Ping" command. "Ping" command comes in prio, so it is guaranteed it will be processed as a first command.
34
34
  sleep RunnerRecoveryStrategies::RestoreConnection::TIME_BETWEEN_RETRIES + CommandsHandler::PULL_INTERVAL + 1
35
- if subscriptions_set_commands_queries.find_by(subscriptions_set_id: subscriptions_set_id, command_name: cmd_name)
35
+ existing_cmd = subscriptions_set_commands_queries.find_by(
36
+ subscriptions_set_id: subscriptions_set_id, command_name: cmd_name
37
+ )
38
+ if existing_cmd
36
39
  # "Ping" command wasn't consumed. Related process must be dead.
37
40
  subscriptions_set_queries.delete(subscriptions_set_id)
38
41
  PgEventstore.logger&.info(
@@ -10,14 +10,14 @@ require_relative 'cli/commands'
10
10
  module PgEventstore
11
11
  module CLI
12
12
  OPTIONS_PARSER = {
13
- "subscriptions" => [Parsers::SubscriptionParser, ParserOptions::SubscriptionOptions].freeze
13
+ 'subscriptions' => [Parsers::SubscriptionParser, ParserOptions::SubscriptionOptions].freeze,
14
14
  }.tap do |directions|
15
15
  directions.default = [Parsers::DefaultParser, ParserOptions::DefaultOptions].freeze
16
16
  end.freeze
17
17
 
18
18
  COMMANDS = {
19
- ["subscriptions", "start"].freeze => Commands::StartSubscriptionsCommand,
20
- ["subscriptions", "stop"].freeze => Commands::StopSubscriptionsCommand
19
+ %w[subscriptions start].freeze => Commands::StartSubscriptionsCommand,
20
+ %w[subscriptions stop].freeze => Commands::StopSubscriptionsCommand,
21
21
  }.freeze
22
22
 
23
23
  class << self
@@ -30,7 +30,7 @@ module PgEventstore
30
30
  # @return [Integer] exit code
31
31
  def execute(args)
32
32
  options_parser_class, options_class = OPTIONS_PARSER[args[0]]
33
- command, parsed_options = options_parser_class.new(ARGV, options_class.new).parse
33
+ command, parsed_options = options_parser_class.new(args, options_class.new).parse
34
34
  return Commands::HelpCommand.new(parsed_options).call if parsed_options.help
35
35
  return COMMANDS[command].new(parsed_options).call if COMMANDS[command]
36
36
 
@@ -48,7 +48,7 @@ module PgEventstore
48
48
  stream_ids.map do |stream_id|
49
49
  filter = {
50
50
  streams: [{ context: partition.context, stream_name: partition.stream_name, stream_id: stream_id }],
51
- event_types: [partition.event_type]
51
+ event_types: [partition.event_type],
52
52
  }
53
53
  options.merge(filter: filter, max_count: 1)
54
54
  end
@@ -60,7 +60,7 @@ module PgEventstore
60
60
  def build_filter_options_for_partitions(partition, options)
61
61
  filter = {
62
62
  streams: [{ context: partition.context, stream_name: partition.stream_name }],
63
- event_types: [partition.event_type]
63
+ event_types: [partition.event_type],
64
64
  }
65
65
  options.merge(filter: filter, max_count: 1)
66
66
  end
@@ -13,6 +13,7 @@ module PgEventstore
13
13
  @partitions = {}
14
14
  @partition_queries = partition_queries
15
15
  end
16
+
16
17
  # @param event [PgEventstore::Event]
17
18
  # @param revision [Integer]
18
19
  # @return [PgEventstore::Event]
@@ -28,12 +28,11 @@ module PgEventstore
28
28
  # @return [void]
29
29
  def check_events_presence(events)
30
30
  ids_from_db = queries.events.ids_from_db(events)
31
- (events.map(&:id) - ids_from_db).tap do |missing_ids|
32
- return if missing_ids.empty?
31
+ missing_ids = events.map(&:id) - ids_from_db
32
+ return if missing_ids.empty?
33
33
 
34
- missing_event = events.find { |event| event.id == missing_ids.first }
35
- raise NotPersistedEventError, missing_event
36
- end
34
+ missing_event = events.find { |event| event.id == missing_ids.first }
35
+ raise NotPersistedEventError, missing_event
37
36
  end
38
37
  end
39
38
  end
@@ -5,9 +5,7 @@ module PgEventstore
5
5
  # @!visibility private
6
6
  class Multiple < AbstractCommand
7
7
  def call(&blk)
8
- queries.transactions.transaction do
9
- yield
10
- end
8
+ queries.transactions.transaction(&blk)
11
9
  end
12
10
  end
13
11
  end
@@ -17,7 +17,7 @@ module PgEventstore
17
17
  end
18
18
 
19
19
  next_revision = calc_next_revision(events, options[:direction])
20
- raise StopIteration if next_revision.negative?
20
+ raise StopIteration if next_revision < 0
21
21
  end
22
22
  end
23
23
  end
@@ -10,7 +10,7 @@ module PgEventstore
10
10
  # @return [String] PostgreSQL connection URI docs
11
11
  # https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING-URIS
12
12
  option(:pg_uri) do
13
- ENV.fetch('PG_EVENTSTORE_URI') { 'postgresql://postgres:postgres@localhost:5432/eventstore' }
13
+ ENV.fetch('PG_EVENTSTORE_URI', 'postgresql://postgres:postgres@localhost:5432/eventstore')
14
14
  end
15
15
  # @!attribute max_count
16
16
  # @return [Integer] Number of events to return in one response when reading from a stream
@@ -63,7 +63,7 @@ module PgEventstore
63
63
  # A shorthand from ConnectionPool#with.
64
64
  # @yieldparam connection [PG::Connection] PostgreSQL connection instance
65
65
  # @return [Object] a value of a given block
66
- def with(&blk)
66
+ def with(&_blk)
67
67
  should_retry = true
68
68
  @pool.with do |conn|
69
69
  yield conn
@@ -72,6 +72,7 @@ module PgEventstore
72
72
  # delay.
73
73
  conn.sync_reset
74
74
  raise unless should_retry
75
+
75
76
  should_retry = false
76
77
  retry
77
78
  end
@@ -85,6 +86,7 @@ module PgEventstore
85
86
  private
86
87
 
87
88
  # @return [ConnectionPool]
89
+ # rubocop:disable Naming/MemoizedInstanceVariableName
88
90
  def init_pool
89
91
  @pool ||= ConnectionPool.new(size: pool_size, timeout: pool_timeout) do
90
92
  PgConnection.new(uri).tap do |conn|
@@ -93,6 +95,7 @@ module PgEventstore
93
95
  end
94
96
  end
95
97
  end
98
+ # rubocop:enable Naming/MemoizedInstanceVariableName
96
99
 
97
100
  # @return [PG::BasicTypeRegistry]
98
101
  def pg_type_registry
@@ -220,6 +220,7 @@ module PgEventstore
220
220
  def initialize(stream, event_types)
221
221
  @stream = stream
222
222
  @event_types = event_types
223
+ super("Missing partitions for stream #{stream.inspect}, event types #{event_types.inspect}")
223
224
  end
224
225
  end
225
226
 
@@ -244,13 +245,14 @@ module PgEventstore
244
245
  end
245
246
  end
246
247
 
247
- class WrappedException < Error
248
+ class WrappedException < StandardError
248
249
  attr_reader :original_exception
249
250
  attr_reader :extra
250
251
 
251
252
  def initialize(original_exception, extra)
252
253
  @original_exception = original_exception
253
254
  @extra = extra
255
+ super()
254
256
  end
255
257
  end
256
258
  end
@@ -71,6 +71,7 @@ module PgEventstore
71
71
  # @param action [String, Symbol]
72
72
  # @param method_name [Symbol]
73
73
  # @return [void]
74
+ # rubocop:disable Naming/PredicatePrefix
74
75
  def has_callbacks(action, method_name)
75
76
  visibility_method = visibility_method(method_name)
76
77
  m = Module.new do
@@ -81,6 +82,7 @@ module PgEventstore
81
82
  end
82
83
  prepend m
83
84
  end
85
+ # rubocop:enable Naming/PredicatePrefix
84
86
 
85
87
  private
86
88
 
@@ -50,20 +50,20 @@ module PgEventstore
50
50
  @metadata = metadata
51
51
  end
52
52
 
53
- # @param other_option [Object]
53
+ # @param other [Object]
54
54
  # @return [Boolean]
55
- def ==(other_option)
56
- return false unless other_option.is_a?(Option)
55
+ def ==(other)
56
+ return false unless other.is_a?(Option)
57
57
 
58
- name == other_option.name
58
+ name == other.name
59
59
  end
60
60
 
61
- # @param other_option [Object]
61
+ # @param other [Object]
62
62
  # @return [Boolean]
63
- def eql?(other_option)
64
- return false unless other_option.is_a?(Option)
63
+ def eql?(other)
64
+ return false unless other.is_a?(Option)
65
65
 
66
- name.eql?(other_option.name)
66
+ name.eql?(other.name)
67
67
  end
68
68
 
69
69
  # @return [Integer]
@@ -73,8 +73,8 @@ module PgEventstore
73
73
  end
74
74
 
75
75
  class Options < Set
76
- def add(o)
77
- @hash[o] = o
76
+ def add(option)
77
+ @hash[option] = option
78
78
  self
79
79
  end
80
80
 
@@ -23,7 +23,7 @@ module PgEventstore
23
23
  Class.new(original_class).tap do |klass|
24
24
  klass.define_singleton_method(:connection) { PgEventstore.connection(config_name) }
25
25
  klass.class_eval do
26
- [:to_s, :inspect, :name].each do |m|
26
+ %i[to_s inspect name].each do |m|
27
27
  define_singleton_method(m, &original_class.method(m))
28
28
  end
29
29
  end
@@ -18,11 +18,13 @@ module PgEventstore
18
18
  def log(sql, params)
19
19
  return unless PgEventstore.logger&.debug?
20
20
 
21
- sql = sql.gsub(/\$\d+/).each do |matched|
22
- value = params[matched[1..].to_i - 1]
23
- value = encode_value(value)
24
- normalize_value(value)
25
- end unless params&.empty?
21
+ unless params&.empty?
22
+ sql = sql.gsub(/\$\d+/).each do |matched|
23
+ value = params[matched[1..].to_i - 1]
24
+ value = encode_value(value)
25
+ normalize_value(value)
26
+ end
27
+ end
26
28
  PgEventstore.logger.debug(sql)
27
29
  end
28
30
 
@@ -48,18 +48,18 @@ module PgEventstore
48
48
  sql_builder.where_or('context = ? and stream_name = ? and type = ?', context, stream_name, event_type)
49
49
  end
50
50
  sql_builder.where('id = ANY(?::uuid[])', events.map(&:id))
51
- PgEventstore.connection.with do |conn|
51
+ raw_events = PgEventstore.connection.with do |conn|
52
52
  conn.exec_params(*sql_builder.to_exec_params)
53
- end.to_a.map { |attrs| attrs['id'] }
53
+ end.to_a
54
+ raw_events.map { |attrs| attrs['id'] }
54
55
  end
55
56
 
56
57
  # @param stream [PgEventstore::Stream]
57
58
  # @return [Integer, nil]
58
59
  def stream_revision(stream)
59
- sql_builder = SQLBuilder.new.from('events').select('stream_revision').
60
- where('context = ? and stream_name = ? and stream_id = ?', *stream.to_a).
61
- order('stream_revision DESC').
62
- limit(1)
60
+ sql_builder = SQLBuilder.new.from('events').select('stream_revision')
61
+ sql_builder.where('context = ? and stream_name = ? and stream_id = ?', *stream.to_a)
62
+ sql_builder.order('stream_revision DESC').limit(1)
63
63
  connection.with do |conn|
64
64
  conn.exec_params(*sql_builder.to_exec_params)
65
65
  end.to_a.dig(0, 'stream_revision')
@@ -86,14 +86,15 @@ module PgEventstore
86
86
  columns = %w[id data metadata stream_revision link_id link_partition_id type context stream_name stream_id]
87
87
 
88
88
  sql = <<~SQL
89
- INSERT INTO events (#{columns.join(', ')})
90
- VALUES #{sql_rows_for_insert.join(", ")}
89
+ INSERT INTO events (#{columns.join(', ')})
90
+ VALUES #{sql_rows_for_insert.join(', ')}
91
91
  RETURNING *
92
92
  SQL
93
93
 
94
- connection.with do |conn|
94
+ raw_events = connection.with do |conn|
95
95
  conn.exec_params(sql, values)
96
- end.map do |raw_event|
96
+ end
97
+ raw_events.map do |raw_event|
97
98
  deserializer.without_middlewares.deserialize(raw_event)
98
99
  end
99
100
  end
@@ -55,7 +55,7 @@ module PgEventstore
55
55
  end
56
56
 
57
57
  partition_sql = <<~SQL
58
- INSERT INTO partitions (#{attributes.keys.join(', ')})
58
+ INSERT INTO partitions (#{attributes.keys.join(', ')})
59
59
  VALUES (#{Utils.positional_vars(attributes.values)}) RETURNING *
60
60
  SQL
61
61
  partition = connection.with do |conn|
@@ -87,7 +87,7 @@ module PgEventstore
87
87
  end
88
88
 
89
89
  partition_sql = <<~SQL
90
- INSERT INTO partitions (#{attributes.keys.join(', ')})
90
+ INSERT INTO partitions (#{attributes.keys.join(', ')})
91
91
  VALUES (#{Utils.positional_vars(attributes.values)}) RETURNING *
92
92
  SQL
93
93
  partition = connection.with do |conn|
@@ -116,8 +116,8 @@ module PgEventstore
116
116
  return unless partition_required?(stream, event_type)
117
117
 
118
118
  context_partition = context_partition(stream) || create_context_partition(stream)
119
- stream_name_partition = stream_name_partition(stream) ||
120
- create_stream_name_partition(stream, context_partition['table_name'])
119
+ stream_name_partition =
120
+ stream_name_partition(stream) || create_stream_name_partition(stream, context_partition['table_name'])
121
121
 
122
122
  create_event_type_partition(stream, event_type, stream_name_partition['table_name'])
123
123
  end