sandthorn_sequel_projection 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +3 -3
- data/lib/sandthorn_sequel_projection.rb +2 -1
- data/lib/sandthorn_sequel_projection/event_store.rb +13 -0
- data/lib/sandthorn_sequel_projection/processed_events_tracker.rb +11 -7
- data/lib/sandthorn_sequel_projection/version.rb +1 -1
- data/sandthorn_sequel_projection.gemspec +3 -3
- data/spec/mock_event_store_spec.rb +30 -0
- data/spec/projection_spec.rb +2 -2
- data/spec/support/mock_event_store.rb +13 -7
- metadata +13 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ed993e1161fdd690cbdc9d687b477bc817d9914
|
4
|
+
data.tar.gz: 761900e638aacf45e73657775e9b933b906b72e8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3aaf8e7a717c7ed0350af0255f899e208b544519c3f43c15bebdde8127e5ba06e96af036e06e4c6259ea06931de67ac975471c9cb0bd797305498dc92e8467a
|
7
|
+
data.tar.gz: ca046141de5a0893faab75c07661244c598bcc4a28d2faad01486e0e541323c6e217fe5f954d2a65474a2ba82a6a7a7eed1fbe453006719001af1adda13102bf
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -56,9 +56,9 @@ SandthornSequelProjection uses Sequel to connected to a database. Configure it l
|
|
56
56
|
# The key is the name of the method to be executed. Filters are defined in the value.
|
57
57
|
# Handlers with only a symbol will execute for all events.
|
58
58
|
define_event_handlers do |handlers|
|
59
|
-
handlers.
|
60
|
-
handlers.
|
61
|
-
handlers.
|
59
|
+
handlers.define new_user: { aggregate_type: MyAggregates::User, event_name: :new }
|
60
|
+
handlers.define foo_changed: { aggregate_types: [MyAggregates::User, MyAggregates::Foo] }
|
61
|
+
handlers.define :wildcard
|
62
62
|
end
|
63
63
|
|
64
64
|
def new_users(event)
|
@@ -6,6 +6,7 @@ require "sandthorn"
|
|
6
6
|
require "sandthorn_sequel_projection/errors"
|
7
7
|
require "sandthorn_sequel_projection/version"
|
8
8
|
require "sandthorn_sequel_projection/utilities"
|
9
|
+
require "sandthorn_sequel_projection/event_store"
|
9
10
|
require "sandthorn_sequel_projection/cursor"
|
10
11
|
require "sandthorn_sequel_projection/event_handler"
|
11
12
|
require "sandthorn_sequel_projection/event_handler_collection"
|
@@ -36,7 +37,7 @@ module SandthornSequelProjection
|
|
36
37
|
end
|
37
38
|
|
38
39
|
def find_event_store(name)
|
39
|
-
|
40
|
+
EventStore.new(name)
|
40
41
|
end
|
41
42
|
end
|
42
43
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SandthornSequelProjection
|
2
|
+
class EventStore
|
3
|
+
def initialize(name = :default)
|
4
|
+
@name = name || :default
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_events(*args)
|
8
|
+
keywords = args.pop || {}
|
9
|
+
keywords[:event_store] = @name
|
10
|
+
Sandthorn.get_events(keywords)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -11,7 +11,7 @@ module SandthornSequelProjection
|
|
11
11
|
|
12
12
|
DEFAULT_TABLE_NAME = :processed_events_trackers
|
13
13
|
|
14
|
-
def initialize(identifier
|
14
|
+
def initialize(identifier: required(:identifier), event_store: required(:event_store), db_connection: nil)
|
15
15
|
@identifier = identifier.to_s
|
16
16
|
@event_store = event_store
|
17
17
|
@db_connection = db_connection || SandthornSequelProjection.configuration.db_connection
|
@@ -29,12 +29,12 @@ module SandthornSequelProjection
|
|
29
29
|
with_lock do
|
30
30
|
cursor = Cursor.new(after_sequence_number: last_processed_sequence_number, event_store: event_store)
|
31
31
|
events = cursor.get_batch
|
32
|
-
|
33
|
-
|
32
|
+
until(events.empty?)
|
33
|
+
transaction do
|
34
34
|
block.call(events)
|
35
|
-
|
35
|
+
write_sequence_number(cursor.last_sequence_number)
|
36
36
|
end
|
37
|
-
|
37
|
+
events = cursor.get_batch
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -70,14 +70,18 @@ module SandthornSequelProjection
|
|
70
70
|
String :identifier
|
71
71
|
Integer :last_processed_sequence_number, default: 0
|
72
72
|
DateTime :locked_at, null: true
|
73
|
+
index [:identifier], unique: true
|
73
74
|
end
|
74
|
-
db_connection.add_index(table_name, :identifier, unique: true)
|
75
75
|
rescue Exception => e
|
76
|
-
raise
|
76
|
+
raise MigrationError, e
|
77
77
|
end
|
78
78
|
|
79
79
|
private
|
80
80
|
|
81
|
+
def required(key)
|
82
|
+
raise ArgumentError, "key missing: #{key}"
|
83
|
+
end
|
84
|
+
|
81
85
|
def write_sequence_number(number)
|
82
86
|
table.where(identifier: identifier).update(last_processed_sequence_number: number)
|
83
87
|
end
|
@@ -18,18 +18,18 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = ">= 2.
|
21
|
+
spec.required_ruby_version = ">= 2.0"
|
22
22
|
|
23
23
|
spec.add_development_dependency "bundler", "~> 1.6"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "rspec"
|
26
|
-
spec.add_development_dependency "sandthorn_driver_sequel"
|
26
|
+
spec.add_development_dependency "sandthorn_driver_sequel", "~> 2.0.0"
|
27
27
|
spec.add_development_dependency "awesome_print"
|
28
28
|
spec.add_development_dependency "pry"
|
29
29
|
spec.add_development_dependency "sqlite3"
|
30
30
|
spec.add_development_dependency "codeclimate-test-reporter"
|
31
31
|
|
32
|
-
spec.add_runtime_dependency "sandthorn", "~> 0.
|
32
|
+
spec.add_runtime_dependency "sandthorn", "~> 0.7"
|
33
33
|
spec.add_runtime_dependency "sandthorn_event_filter", "~> 0.0.4"
|
34
34
|
spec.add_runtime_dependency "sequel"
|
35
35
|
spec.add_runtime_dependency "simple_migrator", "~> 0.0.2"
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module SandthornSequelProjection
|
2
|
+
describe MockEventStore do
|
3
|
+
let(:store) { MockEventStore.new }
|
4
|
+
describe "get_events" do
|
5
|
+
context "when there are events" do
|
6
|
+
before do
|
7
|
+
store.add_event({sequence_number: 1, event_args: { foo: "bar" } })
|
8
|
+
end
|
9
|
+
it "returns events with serialized event data" do
|
10
|
+
events = store.get_events
|
11
|
+
event = events.first
|
12
|
+
expect(event[:event_data]).to eq(YAML.dump(event[:event_args]))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns the correct amount of events" do
|
16
|
+
store.add_event({sequence_number: 2, event_args: { foo: "bar"} })
|
17
|
+
expect(store.get_events(take: 2).length).to eq(2)
|
18
|
+
expect(store.get_events(take: 1).length).to eq(1)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when there's no events" do
|
23
|
+
it "return the empty array" do
|
24
|
+
expect(store.get_events).to be_empty
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/spec/projection_spec.rb
CHANGED
@@ -46,8 +46,8 @@ module SandthornSequelProjection
|
|
46
46
|
before do
|
47
47
|
event_store = Sandthorn.default_event_store
|
48
48
|
event_store.reset
|
49
|
-
event_store.add_event({sequence_number: 1})
|
50
|
-
event_store.add_event({sequence_number: 2})
|
49
|
+
event_store.add_event({sequence_number: 1, event_args: {}})
|
50
|
+
event_store.add_event({sequence_number: 2, event_args: {}})
|
51
51
|
end
|
52
52
|
|
53
53
|
it "fetches events and passes them on to the handlers" do
|
@@ -1,29 +1,35 @@
|
|
1
1
|
require 'json'
|
2
|
-
|
2
|
+
require 'pp'
|
3
3
|
module SandthornSequelProjection
|
4
4
|
class MockEventStore
|
5
5
|
|
6
6
|
def initialize(events = nil)
|
7
|
-
|
7
|
+
Array.wrap(events).each do |event|
|
8
|
+
add_event(event)
|
9
|
+
end
|
8
10
|
end
|
9
11
|
|
10
12
|
def reset(events = [])
|
11
13
|
@events = events
|
12
14
|
end
|
13
15
|
|
16
|
+
def events
|
17
|
+
@events ||= []
|
18
|
+
end
|
19
|
+
|
14
20
|
def add_event(event)
|
15
|
-
|
21
|
+
# We have to do these silly things b/c of Sandthorn design errors.
|
22
|
+
event[:event_data] = Sandthorn.serialize(event[:event_args])
|
23
|
+
events << event
|
16
24
|
end
|
17
25
|
|
18
26
|
alias_method :add, :add_event
|
19
27
|
|
20
|
-
def get_events(after_sequence_number: 0, take: 1)
|
28
|
+
def get_events(after_sequence_number: 0, take: 1, **rest)
|
21
29
|
unless numeric?(after_sequence_number, take)
|
22
30
|
raise ArgumentError, "arguments have to be numbers, received: #{after_sequence_number.inspect} and #{take.inspect}"
|
23
31
|
end
|
24
|
-
|
25
|
-
stop = after_sequence_number + take - 1
|
26
|
-
Array.wrap(@events[start..stop])
|
32
|
+
events.select { |event| event[:sequence_number] > after_sequence_number }.take(take).map { |e| e.dup }
|
27
33
|
end
|
28
34
|
|
29
35
|
def numeric?(*args)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sandthorn_sequel_projection
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lars Krantz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: sandthorn_driver_sequel
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 2.0.0
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
68
|
+
version: 2.0.0
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: awesome_print
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -128,14 +128,14 @@ dependencies:
|
|
128
128
|
requirements:
|
129
129
|
- - "~>"
|
130
130
|
- !ruby/object:Gem::Version
|
131
|
-
version: '0.
|
131
|
+
version: '0.7'
|
132
132
|
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
136
136
|
- - "~>"
|
137
137
|
- !ruby/object:Gem::Version
|
138
|
-
version: '0.
|
138
|
+
version: '0.7'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
140
|
name: sandthorn_event_filter
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -200,6 +200,7 @@ files:
|
|
200
200
|
- lib/sandthorn_sequel_projection/errors.rb
|
201
201
|
- lib/sandthorn_sequel_projection/event_handler.rb
|
202
202
|
- lib/sandthorn_sequel_projection/event_handler_collection.rb
|
203
|
+
- lib/sandthorn_sequel_projection/event_store.rb
|
203
204
|
- lib/sandthorn_sequel_projection/lock.rb
|
204
205
|
- lib/sandthorn_sequel_projection/manifest.rb
|
205
206
|
- lib/sandthorn_sequel_projection/processed_events_tracker.rb
|
@@ -216,6 +217,7 @@ files:
|
|
216
217
|
- spec/event_handler_spec.rb
|
217
218
|
- spec/integration/projection_spec.rb
|
218
219
|
- spec/lock_spec.rb
|
220
|
+
- spec/mock_event_store_spec.rb
|
219
221
|
- spec/processed_events_tracker_spec.rb
|
220
222
|
- spec/projection_spec.rb
|
221
223
|
- spec/runner_spec.rb
|
@@ -235,7 +237,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
235
237
|
requirements:
|
236
238
|
- - ">="
|
237
239
|
- !ruby/object:Gem::Version
|
238
|
-
version: '2.
|
240
|
+
version: '2.0'
|
239
241
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
240
242
|
requirements:
|
241
243
|
- - ">="
|
@@ -243,7 +245,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
243
245
|
version: '0'
|
244
246
|
requirements: []
|
245
247
|
rubyforge_project:
|
246
|
-
rubygems_version: 2.4.
|
248
|
+
rubygems_version: 2.4.3
|
247
249
|
signing_key:
|
248
250
|
specification_version: 4
|
249
251
|
summary: Helps creating sql projections from sandthorn events
|
@@ -253,6 +255,7 @@ test_files:
|
|
253
255
|
- spec/event_handler_spec.rb
|
254
256
|
- spec/integration/projection_spec.rb
|
255
257
|
- spec/lock_spec.rb
|
258
|
+
- spec/mock_event_store_spec.rb
|
256
259
|
- spec/processed_events_tracker_spec.rb
|
257
260
|
- spec/projection_spec.rb
|
258
261
|
- spec/runner_spec.rb
|