simple_event_sourcing 0.9.0 → 1.0.0
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/.gitignore +0 -0
- data/.rspec +0 -0
- data/.simplecov +0 -0
- data/.travis.yml +0 -0
- data/CODE_OF_CONDUCT.md +0 -0
- data/Dockerfile +0 -0
- data/Gemfile +0 -0
- data/Gemfile.lock +1 -1
- data/LICENSE.txt +0 -0
- data/README.md +11 -10
- data/Rakefile +0 -0
- data/docker-compose.yml +0 -0
- data/lib/simple_event_sourcing.rb +0 -0
- data/lib/simple_event_sourcing/aggregate_root/base.rb +5 -2
- data/lib/simple_event_sourcing/aggregate_root/history.rb +0 -0
- data/lib/simple_event_sourcing/aggregate_root/id.rb +3 -5
- data/lib/simple_event_sourcing/events/event.rb +1 -1
- data/lib/simple_event_sourcing/events/event_dispatcher.rb +0 -0
- data/lib/simple_event_sourcing/events/event_store.rb +0 -0
- data/lib/simple_event_sourcing/events/event_store/redis/redis_client.rb +0 -0
- data/lib/simple_event_sourcing/events/event_store/redis/redis_event_store.rb +2 -2
- data/lib/simple_event_sourcing/events/event_subscriber.rb +0 -0
- data/lib/simple_event_sourcing/events/stored_event.rb +1 -1
- data/lib/simple_event_sourcing/version.rb +1 -1
- data/run.sh +0 -0
- data/simple_event_sourcing.gemspec +0 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 74c6944c32361f4df940028e1e7a9d6c7cd2608a5031210e91140084ff8f947a
|
4
|
+
data.tar.gz: 8229b619a34663f4d40c7d60caa188a0acef866aa8a6992fddc5462b04f8d0cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 80722152a7f8094b1644e5e6ee318035da1856cd06f3abc3ea8bf3f4f5967236504054a7a990f231245883e2f09226987783ecf8614e1948c1d389d9c031e9a8
|
7
|
+
data.tar.gz: 5090dfc5ea835f078c29bd6ef3a03c53eda986627a9102969e4f17f21e5b175d61201587bfdbbf82d12ac8a154c511351d212c9521843f4231adf6bcbf41f1cb
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.simplecov
CHANGED
File without changes
|
data/.travis.yml
CHANGED
File without changes
|
data/CODE_OF_CONDUCT.md
CHANGED
File without changes
|
data/Dockerfile
CHANGED
File without changes
|
data/Gemfile
CHANGED
File without changes
|
data/Gemfile.lock
CHANGED
data/LICENSE.txt
CHANGED
File without changes
|
data/README.md
CHANGED
@@ -20,6 +20,7 @@ You could find this base classes:
|
|
20
20
|
- EventDispatcher
|
21
21
|
- EventSubscriber
|
22
22
|
- StoredEvent
|
23
|
+
- EventStore (Facade)
|
23
24
|
- RedisEventStore
|
24
25
|
|
25
26
|
## Installation
|
@@ -47,21 +48,18 @@ class Employee
|
|
47
48
|
|
48
49
|
include SimpleEventSourcing::AggregateRoot::Base
|
49
50
|
|
50
|
-
|
51
|
+
private_class_method :new
|
51
52
|
|
52
|
-
|
53
|
-
super
|
54
|
-
unless args.nil?
|
55
|
-
apply_record_event NewEmployeeIsHiredEvent , name: args[:name], title: args[:title], salary: args[:salary]
|
56
|
-
end
|
57
|
-
end
|
53
|
+
attr_reader :name, :title, :salary
|
58
54
|
|
59
55
|
def salary=(new_salary)
|
60
56
|
apply_record_event SalaryHasChangedEvent , new_salary: new_salary
|
61
57
|
end
|
62
58
|
|
63
|
-
def
|
64
|
-
|
59
|
+
def self.create(name,title,salary)
|
60
|
+
employee = new
|
61
|
+
employee.apply_record_event NewEmployeeIsHiredEvent,name: name,title: title, salary: salary
|
62
|
+
employee
|
65
63
|
end
|
66
64
|
|
67
65
|
on NewEmployeeIsHiredEvent do |event|
|
@@ -78,6 +76,9 @@ end
|
|
78
76
|
|
79
77
|
```
|
80
78
|
|
79
|
+
It´s important to notice use of named constructor "create" in order to leave the constructor for building an aggregate from its events history.
|
80
|
+
|
81
|
+
|
81
82
|
You must create your own domain events
|
82
83
|
|
83
84
|
```ruby
|
@@ -120,7 +121,7 @@ class EmployeeRepository
|
|
120
121
|
end
|
121
122
|
|
122
123
|
def save(employee)
|
123
|
-
employee.
|
124
|
+
employee.publish_events.each do |event|
|
124
125
|
@event_store.commit event
|
125
126
|
SimpleEventSourcing::Events::EventDispatcher.publish(event)
|
126
127
|
end
|
data/Rakefile
CHANGED
File without changes
|
data/docker-compose.yml
CHANGED
File without changes
|
File without changes
|
@@ -7,13 +7,16 @@ module SimpleEventSourcing
|
|
7
7
|
|
8
8
|
def initialize(_args = nil)
|
9
9
|
@events = []
|
10
|
-
@aggregate_id ||= SimpleEventSourcing::Id::UUIDId.generate
|
11
10
|
end
|
12
11
|
|
13
12
|
def have_changed?
|
14
13
|
(@events.count > 0)
|
15
14
|
end
|
16
15
|
|
16
|
+
def count_events
|
17
|
+
@events.count
|
18
|
+
end
|
19
|
+
|
17
20
|
def publish
|
18
21
|
published_events = @events
|
19
22
|
clear_events
|
@@ -26,7 +29,7 @@ module SimpleEventSourcing
|
|
26
29
|
end
|
27
30
|
|
28
31
|
def apply_record_event(event_class, args = {})
|
29
|
-
args[:aggregate_id] ||= aggregate_id
|
32
|
+
args[:aggregate_id] ||= aggregate_id.value
|
30
33
|
event = event_class.new(args)
|
31
34
|
apply_event event
|
32
35
|
record_event event
|
File without changes
|
@@ -5,20 +5,18 @@ module SimpleEventSourcing
|
|
5
5
|
module Id
|
6
6
|
|
7
7
|
class BaseId
|
8
|
+
attr_reader :value
|
9
|
+
|
8
10
|
def initialize(value)
|
9
11
|
@value = value
|
10
12
|
end
|
11
13
|
|
12
|
-
def id
|
13
|
-
@value
|
14
|
-
end
|
15
|
-
|
16
14
|
def to_s
|
17
15
|
@value
|
18
16
|
end
|
19
17
|
|
20
18
|
def ==(other_id)
|
21
|
-
self.class == other_id.class && @value == other_id.
|
19
|
+
self.class == other_id.class && @value == other_id.value
|
22
20
|
end
|
23
21
|
|
24
22
|
alias eql? ==
|
File without changes
|
File without changes
|
File without changes
|
@@ -12,13 +12,13 @@ module SimpleEventSourcing
|
|
12
12
|
def commit(event)
|
13
13
|
|
14
14
|
stored_event = SimpleEventSourcing::Events::StoredEvent.new(
|
15
|
-
aggregate_id: event.aggregate_id
|
15
|
+
aggregate_id: event.aggregate_id,
|
16
16
|
occurred_on: Time.now.getlocal("+02:00").to_i,
|
17
17
|
event_type: event.class.name,
|
18
18
|
event_data: event.to_json
|
19
19
|
)
|
20
20
|
|
21
|
-
@redis.rpush(event.aggregate_id
|
21
|
+
@redis.rpush(event.aggregate_id, stored_event.to_json )
|
22
22
|
|
23
23
|
end
|
24
24
|
|
File without changes
|
@@ -14,7 +14,7 @@ module SimpleEventSourcing
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def to_json(*a)
|
17
|
-
{"aggregate_id" => @aggregate_id
|
17
|
+
{"aggregate_id" => @aggregate_id, "occurred_on" => @occurred_on.to_i, "event_type" => @event_type.to_s, "event_data" => @event_data }.to_json(*a)
|
18
18
|
end
|
19
19
|
|
20
20
|
def self.create_from_json(json)
|
data/run.sh
CHANGED
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_event_sourcing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Manuel López Torrent
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
|
-
rubygems_version: 2.7.
|
153
|
+
rubygems_version: 2.7.2
|
154
154
|
signing_key:
|
155
155
|
specification_version: 4
|
156
156
|
summary: This gem provides a simple way for add events sourcing related behaviour
|