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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86e29f8273b8e6cd8238ada4990bceb29514fc537c567d8e9809b30c467ad86a
4
- data.tar.gz: 0e7cfcb7d53f1d0ec4933c231181700cc10c06733677d43296a914a2e4e104f3
3
+ metadata.gz: 74c6944c32361f4df940028e1e7a9d6c7cd2608a5031210e91140084ff8f947a
4
+ data.tar.gz: 8229b619a34663f4d40c7d60caa188a0acef866aa8a6992fddc5462b04f8d0cb
5
5
  SHA512:
6
- metadata.gz: aa2fdf5c9f120fb9dd51327b9352fad6f51f7ed684a1c66b6e536e6615a6b09602f1109f8b833536210806234ecd374761ef7a4e8b5173ff13fcfdf5fb0927e3
7
- data.tar.gz: ff05314936adc654b36453d3ce7d94d334cd61f6b4f40ad7a1f43b70547de34a7cee72f0946920e49beb7f8bdf882b406be131ce518ff96831496e169debd9ad
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple_event_sourcing (0.9.0)
4
+ simple_event_sourcing (1.0.0)
5
5
  redis
6
6
 
7
7
  GEM
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
- attr_reader :name, :title, :salary
51
+ private_class_method :new
51
52
 
52
- def initialize(args = nil )
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 id
64
- aggregate_id.to_s
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.events.each do |event|
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.id
19
+ self.class == other_id.class && @value == other_id.value
22
20
  end
23
21
 
24
22
  alias eql? ==
@@ -12,7 +12,7 @@ module SimpleEventSourcing
12
12
  end
13
13
 
14
14
  def serialize
15
- {"aggregate_id" => aggregate_id.to_s, "occurred_on" => occurred_on }
15
+ {"aggregate_id" => aggregate_id, "occurred_on" => occurred_on }
16
16
  end
17
17
 
18
18
  def to_json(*a)
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.to_s,
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.to_s, stored_event.to_json )
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.to_s, "occurred_on" => @occurred_on.to_i, "event_type" => @event_type.to_s, "event_data" => @event_data }.to_json(*a)
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)
@@ -1,3 +1,3 @@
1
1
  module SimpleEventSourcing
2
- VERSION = "0.9.0"
2
+ VERSION = '1.0.0'.freeze
3
3
  end
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.9.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-04-30 00:00:00.000000000 Z
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.6
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