ev 0.0.2

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6bb658471b7bb5e4309bde1938a8a099655d78a7
4
+ data.tar.gz: dfe76bb3ca431076ae2998094871141b12d3c90c
5
+ SHA512:
6
+ metadata.gz: ff88b298c2676ad6ee4e96bba5685e3a82ec18ab987b88feb130abb48ae5057945be08cd0acfcbe21ca5ccb1d7e077be65937cb8a73363fbd234fef04e38c276
7
+ data.tar.gz: 12464c8a2f69acda69e45d1ad90a036853dc9eba7a42706551ce712401de1559540e513484967678ed56649d9a93a5304f6309cf79eae4d81cbfcdbde44af517
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ Gemfile.lock
2
+ ev-*.gem
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.2.1
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Matthew Conger-Eldeen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # ev
2
+ Event sourcing tools
data/ev.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ev/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ev"
7
+ s.version = EV::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matthew Conger-Eldeen"]
10
+ s.email = ["mceldeen@gmail.com"]
11
+ s.homepage = "https://www.github.com/mceldeen/ev"
12
+ s.summary = %q{A set of useful stuff for event sourcing.}
13
+ s.description = %q{A set of useful stuff for event sourcing.}
14
+
15
+ s.add_development_dependency "rspec", "~>3.2"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ end
@@ -0,0 +1,58 @@
1
+ module EV
2
+ class EventRoot
3
+ def self.new_from_events(events)
4
+ allocate.tap do |root|
5
+ root.initialize_from_events(events)
6
+ end
7
+ end
8
+
9
+ def initialize_from_events(events)
10
+ events.each do |event|
11
+ apply_without_changes(event)
12
+ end
13
+ end
14
+
15
+ def version
16
+ @version || 0
17
+ end
18
+
19
+ def changes
20
+ if @changes
21
+ @changes.dup
22
+ else
23
+ []
24
+ end
25
+ end
26
+
27
+ def initial_version
28
+ version - changes.size
29
+ end
30
+
31
+ def dirty?
32
+ changes.size > 0
33
+ end
34
+
35
+ def commit
36
+ @changes.clear if @changes
37
+ end
38
+
39
+ protected
40
+
41
+ def handle(event)
42
+ raise NotImplementedError
43
+ end
44
+
45
+ def apply(event)
46
+ apply_without_changes(event)
47
+ @changes ||= []
48
+ @changes << event
49
+ end
50
+
51
+ private
52
+
53
+ def apply_without_changes(event)
54
+ handle(event)
55
+ @version = version.next
56
+ end
57
+ end
58
+ end
data/lib/ev/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module EV
2
+ VERSION = "0.0.2"
3
+ end
data/lib/ev.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ev/event_root'
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+ require_relative '../../../lib/ev/event_root'
3
+
4
+ module EV
5
+ class DummyModel < EventRoot
6
+ def handle(event)
7
+ end
8
+ end
9
+
10
+ describe EventRoot do
11
+ describe ".new_from_events" do
12
+ subject { EventRoot }
13
+
14
+ it "does not call new" do
15
+ expect(subject).to_not receive(:new)
16
+ subject.new_from_events([])
17
+ end
18
+
19
+ describe "with events" do
20
+ before do
21
+ root = EventRoot.new
22
+ expect(root).to receive(:handle).twice
23
+ expect(subject).to receive(:allocate).and_return(root)
24
+ end
25
+
26
+ it "calls handle for each event" do
27
+ subject.new_from_events([1, 2])
28
+ end
29
+
30
+ it "does not show changes" do
31
+ root = subject.new_from_events([1, 2])
32
+ expect(root.changes).to eq([])
33
+ end
34
+
35
+ it "increments the verison number" do
36
+ root = subject.new_from_events([1, 2])
37
+ expect(root.version).to eq(2)
38
+ end
39
+ end
40
+ end
41
+
42
+ describe "#apply" do
43
+ subject { EventRoot.new }
44
+ before do
45
+ @event = {foo: :bar}
46
+ expect(subject).to receive(:handle).with(@event)
47
+ end
48
+
49
+ it "calls handle" do
50
+ subject.send(:apply, @event)
51
+ end
52
+
53
+ it "increments version" do
54
+ expect(subject.version).to eq(0)
55
+ subject.send(:apply, @event)
56
+ expect(subject.version).to eq(1)
57
+ end
58
+
59
+ it "shows changes" do
60
+ expect(subject.changes).to eq([])
61
+ subject.send(:apply, @event)
62
+ expect(subject.changes).to eq([@event])
63
+ end
64
+
65
+ it "duplicates the changes list" do
66
+ subject.send(:apply, @event)
67
+ subject.changes.shift
68
+ expect(subject.changes.size).to eq(1)
69
+ end
70
+ end
71
+
72
+ describe "#initial_version" do
73
+ subject { DummyModel.new_from_events([1, 2])}
74
+
75
+ it "works with no changes" do
76
+ expect(subject.initial_version).to eq(2)
77
+ end
78
+
79
+ it "works with changes" do
80
+ subject.send(:apply, 3)
81
+ expect(subject.initial_version).to eq(2)
82
+ end
83
+ end
84
+
85
+ describe "#dirty?" do
86
+ subject { DummyModel.new_from_events([1,2]) }
87
+
88
+ it "works with no changes" do
89
+ expect(subject.dirty?).to eq(false)
90
+ end
91
+
92
+ it "works with changes" do
93
+ subject.send(:apply, 3)
94
+ expect(subject.dirty?).to eq(true)
95
+ end
96
+ end
97
+
98
+ describe "#commit" do
99
+ subject { DummyModel.new_from_events([1,2]) }
100
+
101
+ it "works with no changes" do
102
+ subject.commit
103
+ expect(subject.dirty?).to eq(false)
104
+ end
105
+
106
+ it "works with changes" do
107
+ subject.send(:apply, 3)
108
+ subject.commit
109
+ expect(subject.dirty?).to eq(false)
110
+ end
111
+ end
112
+ end
113
+ end
@@ -0,0 +1,12 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |expectations|
3
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
4
+ end
5
+
6
+ config.mock_with :rspec do |mocks|
7
+ mocks.verify_partial_doubles = true
8
+ end
9
+
10
+ config.filter_run :focus
11
+ config.run_all_when_everything_filtered = true
12
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ev
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Conger-Eldeen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.2'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.2'
27
+ description: A set of useful stuff for event sourcing.
28
+ email:
29
+ - mceldeen@gmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".ruby-version"
37
+ - Gemfile
38
+ - LICENSE
39
+ - README.md
40
+ - ev.gemspec
41
+ - lib/ev.rb
42
+ - lib/ev/event_root.rb
43
+ - lib/ev/version.rb
44
+ - spec/lib/shift/aggregate_base_spec.rb
45
+ - spec/spec_helper.rb
46
+ homepage: https://www.github.com/mceldeen/ev
47
+ licenses: []
48
+ metadata: {}
49
+ post_install_message:
50
+ rdoc_options: []
51
+ require_paths:
52
+ - lib
53
+ required_ruby_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: '0'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ requirements: []
64
+ rubyforge_project:
65
+ rubygems_version: 2.4.5
66
+ signing_key:
67
+ specification_version: 4
68
+ summary: A set of useful stuff for event sourcing.
69
+ test_files: []