aggregate_root 0.42.0 → 1.1.1
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 +4 -4
- data/Gemfile +1 -1
- data/README.md +1 -120
- data/aggregate_root.gemspec +1 -1
- data/lib/aggregate_root.rb +1 -1
- data/lib/aggregate_root/default_apply_strategy.rb +6 -2
- data/lib/aggregate_root/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 575d73220efb808a61b60b44146f2eea8a960909bd6ef0910a5d1ffe532ddd65
|
4
|
+
data.tar.gz: 4a49b55c2564c1c265f39abe678387f9f0186053d69ff9d33e92c239b55ac283
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a343be272171b21cf995e74f9a69897f60bf1cccdcc5d8fab27b7bcc2d00af490574c3919016f9fbf20a1183eac1cca7c21ceaf604a6c8b7bae21550287866b6
|
7
|
+
data.tar.gz: 3eca1fc0b2bedf6357fa533e3336c76f47eada248806fdb47b3af518b9394f59c22d754b18eb848cb9c20cf9690b331741c8035605d545e09e5efca8828c9e2f
|
data/Gemfile
CHANGED
@@ -8,5 +8,5 @@ eval_gemfile File.expand_path('../support/bundler/Gemfile.shared', __dir__)
|
|
8
8
|
|
9
9
|
gem 'ruby_event_store', path: '../ruby_event_store'
|
10
10
|
gem 'protobuf_nested_struct'
|
11
|
-
gem 'google-protobuf', '~> 3.
|
11
|
+
gem 'google-protobuf', '~> 3.12.2', '>= 3.12.2'
|
12
12
|
gem 'activesupport', '~> 5.0'
|
data/README.md
CHANGED
@@ -2,123 +2,4 @@
|
|
2
2
|
|
3
3
|
Event sourced (with Rails Event Store) aggregate root implementation.
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
* Add following line to your application's Gemfile:
|
8
|
-
|
9
|
-
```ruby
|
10
|
-
gem 'aggregate_root'
|
11
|
-
```
|
12
|
-
|
13
|
-
## Before use
|
14
|
-
|
15
|
-
Choose your weapon now! Ekhm I mean choose your event store client.
|
16
|
-
To do so add configuration in environment setup. Example using [RailsEventStore](https://github.com/RailsEventStore/rails_event_store/):
|
17
|
-
|
18
|
-
```ruby
|
19
|
-
AggregateRoot.configure do |config|
|
20
|
-
config.default_event_store = RailsEventStore::Client.new
|
21
|
-
end
|
22
|
-
```
|
23
|
-
|
24
|
-
Remember that this is only a default event store used by `AggregateRoot` module when no event store is given in `load` / `store` methods parameters.
|
25
|
-
|
26
|
-
To use [RailsEventStore](https://github.com/RailsEventStore/rails_event_store/) add to Gemfile:
|
27
|
-
|
28
|
-
```ruby
|
29
|
-
gem 'rails_event_store'
|
30
|
-
```
|
31
|
-
|
32
|
-
Then setup [RailsEventStore](https://github.com/RailsEventStore/rails_event_store/) as described in
|
33
|
-
the [docs](https://railseventstore.org/docs/install/)
|
34
|
-
|
35
|
-
## Usage
|
36
|
-
|
37
|
-
To create a new aggregate domain object include `AggregateRoot::Base` module.
|
38
|
-
It is important to assign `id` at initializer - it will be used as a event store stream name.
|
39
|
-
|
40
|
-
```ruby
|
41
|
-
class Order
|
42
|
-
include AggregateRoot
|
43
|
-
|
44
|
-
# ... more later
|
45
|
-
end
|
46
|
-
```
|
47
|
-
|
48
|
-
#### Define aggregate logic
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
OrderSubmitted = Class.new(RailsEventStore::Event)
|
52
|
-
OrderExpired = Class.new(RailsEventStore::Event)
|
53
|
-
```
|
54
|
-
|
55
|
-
```ruby
|
56
|
-
class Order
|
57
|
-
include AggregateRoot
|
58
|
-
HasBeenAlreadySubmitted = Class.new(StandardError)
|
59
|
-
HasExpired = Class.new(StandardError)
|
60
|
-
|
61
|
-
def initialize
|
62
|
-
self.state = :new
|
63
|
-
# any other code here
|
64
|
-
end
|
65
|
-
|
66
|
-
def submit
|
67
|
-
raise HasBeenAlreadySubmitted if state == :submitted
|
68
|
-
raise HasExpired if state == :expired
|
69
|
-
apply OrderSubmitted.new(data: {delivery_date: Time.now + 24.hours})
|
70
|
-
end
|
71
|
-
|
72
|
-
def expire
|
73
|
-
apply OrderExpired.new
|
74
|
-
end
|
75
|
-
|
76
|
-
private
|
77
|
-
attr_accessor :state
|
78
|
-
|
79
|
-
def apply_order_submitted(event)
|
80
|
-
self.state = :submitted
|
81
|
-
end
|
82
|
-
|
83
|
-
def apply_order_expired(event)
|
84
|
-
self.state = :expired
|
85
|
-
end
|
86
|
-
end
|
87
|
-
```
|
88
|
-
|
89
|
-
#### Loading an aggregate root object from event store
|
90
|
-
|
91
|
-
```ruby
|
92
|
-
stream_name = "Order$123"
|
93
|
-
order = Order.new.load(stream_name)
|
94
|
-
```
|
95
|
-
|
96
|
-
Load gets all domain event stored for the aggregate in event store and apply them
|
97
|
-
in order to given aggregate to rebuild aggregate's state.
|
98
|
-
|
99
|
-
#### Storing an aggregate root's changes in event store
|
100
|
-
|
101
|
-
```ruby
|
102
|
-
stream_name = "Order$123"
|
103
|
-
order = Order.new.load(stream_name)
|
104
|
-
order.submit
|
105
|
-
order.store
|
106
|
-
```
|
107
|
-
|
108
|
-
Store gets all unpublished aggregate's domain events (created by executing a domain logic method like `submit`)
|
109
|
-
and publish them in order of creation to event store. If `stream_name` is not specified events will be stored
|
110
|
-
in the same stream from which order has been loaded.
|
111
|
-
|
112
|
-
#### Resources
|
113
|
-
|
114
|
-
There're already few blog posts about building an event sourced applications with [rails_event_store](https://github.com/RailsEventStore/rails_event_store) and aggregate_root gems:
|
115
|
-
|
116
|
-
* [Why use Event Sourcing](https://blog.arkency.com/2015/03/why-use-event-sourcing/)
|
117
|
-
* [The Event Store for Rails developers](https://blog.arkency.com/2015/04/the-event-store-for-rails-developers/)
|
118
|
-
* [Fast introduction to Event Sourcing for Ruby programmers](https://blog.arkency.com/2015/03/fast-introduction-to-event-sourcing-for-ruby-programmers/)
|
119
|
-
* [Building an Event Sourced application using rails_event_store](https://blog.arkency.com/2015/05/building-an-event-sourced-application-using-rails-event-store/)
|
120
|
-
* [Using domain events as success/failure messages](https://blog.arkency.com/2015/05/using-domain-events-as-success-slash-failure-messages/)
|
121
|
-
* [Subscribing for events in rails_event_store](https://blog.arkency.com/2015/06/subscribing-for-events-in-rails-event-store/)
|
122
|
-
* [Testing an Event Sourced application](https://blog.arkency.com/2015/07/testing-event-sourced-application/)
|
123
|
-
* [Testing Event Sourced application - the read side](https://blog.arkency.com/2015/09/testing-event-sourced-application-the-read-side/)
|
124
|
-
* [One event to rule them all](https://blog.arkency.com/2016/01/one-event-to-rule-them-all/)
|
5
|
+
For configuration & usage documentation see [Event Sourcing with AggregateRoot](https://railseventstore.org/docs/app/).
|
data/aggregate_root.gemspec
CHANGED
data/lib/aggregate_root.rb
CHANGED
@@ -65,7 +65,7 @@ module AggregateRoot
|
|
65
65
|
Module.new do
|
66
66
|
def self.included(host_class)
|
67
67
|
host_class.extend OnDSL
|
68
|
-
host_class.include AggregateRoot.with_strategy(->
|
68
|
+
host_class.include AggregateRoot.with_strategy(->{ DefaultApplyStrategy.new })
|
69
69
|
end
|
70
70
|
end
|
71
71
|
end
|
@@ -20,10 +20,14 @@ module AggregateRoot
|
|
20
20
|
private
|
21
21
|
|
22
22
|
def handler_name(aggregate, event)
|
23
|
-
aggregate
|
23
|
+
on_dsl_handler_name(aggregate, event.event_type) || apply_handler_name(event.event_type)
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
26
|
+
def on_dsl_handler_name(aggregate, event_type)
|
27
|
+
aggregate.class.on_methods[event_type] if aggregate.class.respond_to?(:on_methods)
|
28
|
+
end
|
29
|
+
|
30
|
+
def apply_handler_name(event_type)
|
27
31
|
"apply_#{Transform.to_snake_case(event_type(event_type))}"
|
28
32
|
end
|
29
33
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aggregate_root
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Arkency
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_event_store
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.1.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.1.1
|
27
27
|
description: Event sourced (with Rails Event Store) aggregate root implementation
|
28
28
|
email:
|
29
29
|
- dev@arkency.com
|
@@ -66,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
66
66
|
- !ruby/object:Gem::Version
|
67
67
|
version: '0'
|
68
68
|
requirements: []
|
69
|
-
rubygems_version: 3.0.
|
69
|
+
rubygems_version: 3.0.3
|
70
70
|
signing_key:
|
71
71
|
specification_version: 4
|
72
72
|
summary: Event sourced (with Rails Event Store) aggregate root implementation
|