rails_event_store 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/rails_event_store.rb +1 -1
- data/lib/rails_event_store/aggregate_root.rb +3 -1
- data/lib/rails_event_store/event_entity.rb +7 -7
- data/lib/rails_event_store/models/event.rb +12 -0
- data/lib/rails_event_store/repositories/event_repository.rb +21 -20
- data/lib/rails_event_store/version.rb +1 -1
- data/rails_event_store.gemspec +3 -0
- metadata +32 -4
- data/lib/rails_event_store/utils/string_utils.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e7e79b6ac4baf7aefef23a90ef89ca16e8704b4
|
4
|
+
data.tar.gz: a4fd3f1e1fd6ab6ce86b8bdf8c4cb52474c47546
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9da2db327c6968a2614fa7a4b2ca570ef3394db5e8fdd573a9a85ac90e0d7c3fc77cabd116c27d2f2893f84488fe4d89dfec0ef3c4b3553aa301f3b38da8c0e7
|
7
|
+
data.tar.gz: 42f2f823e3a1d4e72b2c2e9c136e58732bbea338df6eb3528209141f24fa7d418c9220c8f1d0449ebd86fe2a33f2869f86afd6be3f56f55b4a5a31233741ab39
|
data/README.md
CHANGED
@@ -131,7 +131,7 @@ client.subscribe(invoice, ['PriceChanged', 'ProductAdded'])
|
|
131
131
|
|
132
132
|
```ruby
|
133
133
|
invoice = InvoiceReadModel.new
|
134
|
-
client.
|
134
|
+
client.subscribe_to_all_events(invoice)
|
135
135
|
```
|
136
136
|
|
137
137
|
#### Resources
|
@@ -142,3 +142,11 @@ There're already few blogposts about Rails EventStore. Check them out:
|
|
142
142
|
* [The Event Store for Rails developers](http://blog.arkency.com/2015/04/the-event-store-for-rails-developers/)
|
143
143
|
* [Fast introduction to Event Sourcing for Ruby programmers](http://blog.arkency.com/2015/03/fast-introduction-to-event-sourcing-for-ruby-programmers/)
|
144
144
|
* [Why I want to introduce mutation testing to the rails_event_store gem](http://blog.arkency.com/2015/04/why-i-want-to-introduce-mutation-testing-to-the-rails-event-store-gem/)
|
145
|
+
|
146
|
+
## About
|
147
|
+
|
148
|
+
<img src="http://arkency.com/images/arkency.png" alt="Arkency" width="20%" align="left" />
|
149
|
+
|
150
|
+
Rails Event Store is funded and maintained by Arkency. Check out our other [open-source projects](https://github.com/arkency).
|
151
|
+
|
152
|
+
You can also [hire us](http://arkency.com) or [read our blog](http://blog.arkency.com).
|
data/lib/rails_event_store.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rails_event_store/event_entity'
|
2
|
+
require 'rails_event_store/models/event'
|
2
3
|
require 'rails_event_store/generators/migrate_generator'
|
3
4
|
require 'rails_event_store/generators/templates/migration_template'
|
4
5
|
require 'rails_event_store/version'
|
@@ -10,4 +11,3 @@ require 'rails_event_store/aggregate_root'
|
|
10
11
|
require 'rails_event_store/errors'
|
11
12
|
require 'rails_event_store/client'
|
12
13
|
require 'rails_event_store/constants'
|
13
|
-
require 'rails_event_store/utils/string_utils'
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
|
1
3
|
module RailsEventStore
|
2
4
|
module AggregateRoot
|
3
5
|
def apply(event)
|
@@ -16,7 +18,7 @@ module RailsEventStore
|
|
16
18
|
private
|
17
19
|
|
18
20
|
def apply_event(event)
|
19
|
-
|
21
|
+
send("apply_#{event.event_type.underscore.gsub('/', '_')}", event)
|
20
22
|
end
|
21
23
|
|
22
24
|
def generate_uuid
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require '
|
1
|
+
require 'active_model'
|
2
2
|
|
3
3
|
module RailsEventStore
|
4
|
-
class EventEntity
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
class EventEntity
|
5
|
+
include ::ActiveModel::Model
|
6
|
+
|
7
|
+
attr_accessor :id, :stream, :event_type, :event_id,
|
8
|
+
:metadata, :data, :created_at
|
9
9
|
end
|
10
|
-
end
|
10
|
+
end
|
@@ -3,54 +3,55 @@ module RailsEventStore
|
|
3
3
|
class EventRepository
|
4
4
|
|
5
5
|
def initialize
|
6
|
-
@adapter =
|
6
|
+
@adapter = ::RailsEventStore::Models::Event
|
7
7
|
end
|
8
8
|
attr_reader :adapter
|
9
9
|
|
10
10
|
def find(condition)
|
11
|
-
adapter.where(condition).first
|
11
|
+
build_event_entity adapter.where(condition).first
|
12
12
|
end
|
13
13
|
|
14
14
|
def create(data)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
raise EventCannotBeSaved
|
19
|
-
end
|
15
|
+
build_event_entity adapter.create(data)
|
16
|
+
rescue ActiveRecord::RecordNotUnique
|
17
|
+
raise EventCannotBeSaved
|
20
18
|
end
|
21
19
|
|
22
20
|
def delete(condition)
|
23
21
|
adapter.destroy_all condition
|
22
|
+
nil
|
24
23
|
end
|
25
24
|
|
26
25
|
def get_all_events
|
27
|
-
adapter.find(:all, order: 'stream').map &method(:
|
26
|
+
adapter.find(:all, order: 'stream').map &method(:build_event_entity)
|
28
27
|
end
|
29
28
|
|
30
29
|
def last_stream_event(stream_name)
|
31
|
-
adapter.where(stream: stream_name).last.map &method(:
|
30
|
+
adapter.where(stream: stream_name).last.map &method(:build_event_entity)
|
32
31
|
end
|
33
32
|
|
34
33
|
def load_all_events_forward(stream_name)
|
35
|
-
adapter.where(stream: stream_name).order('id ASC').map &method(:
|
34
|
+
adapter.where(stream: stream_name).order('id ASC').map &method(:build_event_entity)
|
36
35
|
end
|
37
36
|
|
38
37
|
def load_events_batch(stream_name, start_point, count)
|
39
|
-
adapter.where('id >= ? AND stream = ?', start_point, stream_name).limit(count).map &method(:
|
38
|
+
adapter.where('id >= ? AND stream = ?', start_point, stream_name).limit(count).map &method(:build_event_entity)
|
40
39
|
end
|
41
40
|
|
42
41
|
private
|
43
42
|
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
43
|
+
def build_event_entity(record)
|
44
|
+
::RailsEventStore::EventEntity.new(
|
45
|
+
id: record.id,
|
46
|
+
stream: record.stream,
|
47
|
+
event_type: record.event_type,
|
48
|
+
event_id: record.event_id,
|
49
|
+
metadata: record.metadata,
|
50
|
+
data: record.data,
|
51
|
+
created_at: record.created_at
|
52
|
+
)
|
53
53
|
end
|
54
|
+
|
54
55
|
end
|
55
56
|
end
|
56
57
|
end
|
data/rails_event_store.gemspec
CHANGED
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_development_dependency 'rspec'
|
25
25
|
spec.add_development_dependency 'rails', '~> 4.2.1'
|
26
26
|
spec.add_development_dependency 'webmock', '~> 1.21.0'
|
27
|
+
|
27
28
|
spec.add_dependency 'ruby_event_store'
|
29
|
+
spec.add_dependency 'activesupport', '>= 3.0'
|
30
|
+
spec.add_dependency 'activemodel', '>= 3.0'
|
28
31
|
|
29
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rybex
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,34 @@ dependencies:
|
|
108
108
|
- - ">="
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: activesupport
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '3.0'
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '3.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activemodel
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
111
139
|
description: Implementation of Event Store in Ruby
|
112
140
|
email:
|
113
141
|
- tomek.rybka@gmail.com
|
@@ -132,9 +160,9 @@ files:
|
|
132
160
|
- lib/rails_event_store/event_handlers/slack_event_handler.rb
|
133
161
|
- lib/rails_event_store/generators/migrate_generator.rb
|
134
162
|
- lib/rails_event_store/generators/templates/migration_template.rb
|
163
|
+
- lib/rails_event_store/models/event.rb
|
135
164
|
- lib/rails_event_store/repositories/aggregate_repository.rb
|
136
165
|
- lib/rails_event_store/repositories/event_repository.rb
|
137
|
-
- lib/rails_event_store/utils/string_utils.rb
|
138
166
|
- lib/rails_event_store/version.rb
|
139
167
|
- rails_event_store.gemspec
|
140
168
|
homepage: ''
|
@@ -156,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
184
|
version: '0'
|
157
185
|
requirements: []
|
158
186
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.4.
|
187
|
+
rubygems_version: 2.4.8
|
160
188
|
signing_key:
|
161
189
|
specification_version: 4
|
162
190
|
summary: Implementation of Event Store in Ruby
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module StringUtils
|
2
|
-
def self.underscore(camel_cased_word)
|
3
|
-
acronym_regex = /(?=a)b/
|
4
|
-
return camel_cased_word unless camel_cased_word =~ /[A-Z-]|::/
|
5
|
-
word = camel_cased_word.to_s.gsub(/::/, '/')
|
6
|
-
word.gsub!(/(?:(?<=([A-Za-z\d]))|\b)(#{acronym_regex})(?=\b|[^a-z])/) { "#{$1 && '_'}#{$2.downcase}" }
|
7
|
-
word.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
8
|
-
word.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
9
|
-
word.tr!("-", "_")
|
10
|
-
word.downcase!
|
11
|
-
word.gsub!(/[^A-Za-z0-9_]/, '_')
|
12
|
-
word
|
13
|
-
end
|
14
|
-
end
|