rails_simple_event_sourcing 1.0.11 → 1.0.12

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: 0e55cdcaaea329dd389ea7bd44f539e6b676c45d5f0f400cf3cbdd0a67f61021
4
- data.tar.gz: ca8f42fb05104799d8ab73eb14290cc5941b0e05b4b504d8c3f8ba3dde26c971
3
+ metadata.gz: d389be62e627ddf2443c6e7d781d1abbab7aaacf7b908741a753e4dbe370c978
4
+ data.tar.gz: 4dea2cb2546bd903a566edff8f0fb192be5b02ae1f45f36004cf58ba7d30a64a
5
5
  SHA512:
6
- metadata.gz: 41c3718c3caadc0d5cbe82f87158b540c9e78831c4342bc37f582fc28b38cd1ec77f58ec02c8083cd9dde321c6cbe8aa29aded5a96456c6eac7a2e25ead78fc6
7
- data.tar.gz: a53c32406b3a37e448af71401524e85d4f03afdf9dc59d68e4c286ad32030686f1cf4ab961f63b86fb1f4037cb7d996c5128541b474f1db2a817a0b258c9abfa
6
+ metadata.gz: 2e7671967605ab8714cdb39dec920b7fc1449bf4c4adedd77cf409fa89db7497e2f462c1176decb149d9191b01cdd973e88708de836c8f7f88bef98328246608
7
+ data.tar.gz: a3543ef2e0dd176bb85099be1b4d65e9cc0f148644eb5011435920325447114218f84fff9fa6a4721d462e35c2d1568f9ba4665648ff27b26fc7d3cdab550526
data/README.md CHANGED
@@ -177,6 +177,7 @@ Handlers can be discovered in two ways:
177
177
  **Result Object:**
178
178
  The `Result` class has three fields:
179
179
  - `success?` - Boolean indicating if the operation succeeded
180
+ - `failure?` - Boolean indicating if the operation failed (inverse of `success?`)
180
181
  - `data` - Data to return (usually the aggregate/model instance)
181
182
  - `errors` - Array or hash of error messages when `success?` is false
182
183
 
@@ -194,7 +195,7 @@ It supports a chainable API for use in controllers:
194
195
  - `on_success { |data| }` - Executes the block (yielding `data`) if the result is successful
195
196
  - `on_failure { |errors| }` - Executes the block (yielding `errors`) if the result failed
196
197
 
197
- Both methods return `self`, so they can be chained. The predicate `success?` remains available for use in conditionals and tests.
198
+ Both methods return `self`, so they can be chained. The predicates `success?` and `failure?` remain available for use in conditionals and tests.
198
199
 
199
200
  ```ruby
200
201
  result = RailsSimpleEventSourcing::Result.success(data: customer)
@@ -205,9 +206,10 @@ result
205
206
  .on_failure { |errors| render json: { errors: }, status: :unprocessable_entity }
206
207
 
207
208
  # Predicate (preferred in tests)
208
- result.success? # => true
209
- result.data # => #<Customer ...>
210
- result.errors # => nil
209
+ result.success? # => true
210
+ result.failure? # => false
211
+ result.data # => #<Customer ...>
212
+ result.errors # => nil
211
213
  ```
212
214
 
213
215
  **Helper Methods in Handlers:**
@@ -223,9 +225,9 @@ class Customer
223
225
  class Create < RailsSimpleEventSourcing::CommandHandlers::Base
224
226
  def call
225
227
  event = Customer::Events::CustomerCreated.create(
226
- first_name: @command.first_name,
227
- last_name: @command.last_name,
228
- email: @command.email,
228
+ first_name: command.first_name,
229
+ last_name: command.last_name,
230
+ email: command.email,
229
231
  created_at: Time.zone.now,
230
232
  updated_at: Time.zone.now
231
233
  )
@@ -245,9 +247,9 @@ class Customer
245
247
  class Create < RailsSimpleEventSourcing::CommandHandlers::Base
246
248
  def call
247
249
  event = Customer::Events::CustomerCreated.create(
248
- first_name: @command.first_name,
249
- last_name: @command.last_name,
250
- email: @command.email,
250
+ first_name: command.first_name,
251
+ last_name: command.last_name,
252
+ email: command.email,
251
253
  created_at: Time.zone.now,
252
254
  updated_at: Time.zone.now
253
255
  )
@@ -3,8 +3,6 @@
3
3
  module RailsSimpleEventSourcing
4
4
  module CommandHandlers
5
5
  class Base
6
- delegate :success, :failure, to: 'RailsSimpleEventSourcing::Result'
7
-
8
6
  def initialize(command:)
9
7
  @command = command
10
8
  end
@@ -12,6 +10,18 @@ module RailsSimpleEventSourcing
12
10
  def call
13
11
  raise NotImplementedError, "You must implement #{self.class}#call"
14
12
  end
13
+
14
+ private
15
+
16
+ attr_reader :command
17
+
18
+ def success(data: nil)
19
+ Result.success(data:)
20
+ end
21
+
22
+ def failure(errors:)
23
+ Result.failure(errors:)
24
+ end
15
25
  end
16
26
  end
17
27
  end
@@ -25,6 +25,10 @@ module RailsSimpleEventSourcing
25
25
  @success
26
26
  end
27
27
 
28
+ def failure?
29
+ !@success
30
+ end
31
+
28
32
  def on_success(&block)
29
33
  raise ArgumentError, 'Block required' unless block
30
34
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsSimpleEventSourcing
4
- VERSION = '1.0.11'
4
+ VERSION = '1.0.12'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_simple_event_sourcing
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.11
4
+ version: 1.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damian Baćkowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-03-12 00:00:00.000000000 Z
11
+ date: 2026-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pg