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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d389be62e627ddf2443c6e7d781d1abbab7aaacf7b908741a753e4dbe370c978
|
|
4
|
+
data.tar.gz: 4dea2cb2546bd903a566edff8f0fb192be5b02ae1f45f36004cf58ba7d30a64a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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?
|
|
209
|
-
result.
|
|
210
|
-
result.
|
|
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:
|
|
227
|
-
last_name:
|
|
228
|
-
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:
|
|
249
|
-
last_name:
|
|
250
|
-
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
|
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.
|
|
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-
|
|
11
|
+
date: 2026-03-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: pg
|