ruby_event_store 0.5.0 → 0.6.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/.travis.yml +1 -1
- data/CHANGELOG.md +7 -0
- data/CONTRIBUTING.md +27 -0
- data/Makefile +21 -0
- data/README.md +10 -1
- data/lib/ruby_event_store.rb +1 -0
- data/lib/ruby_event_store/projection.rb +56 -0
- data/lib/ruby_event_store/pub_sub/broker.rb +16 -4
- data/lib/ruby_event_store/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ae9a071c07547c47d1e9f3ecfdfdc451e9ce235
|
4
|
+
data.tar.gz: 9271a2095a44bceedbe8b4908a6deaff0be50d19
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a86709c96b0819bbfccff72ae50d27c9813e0bdc7a30a48a6c5a1c41613a3e2aec81cd8def32d96c89e29147ed6d0e5087d664e98a2fcde1fd7b3783664a25a2
|
7
|
+
data.tar.gz: 77c426dfe5eb9e7314f4a86f3d15cddae2acf5b05064427eea7e64fc343cf27532a9d439a2ffd0a5546a5597c67be64a75eba9ecdb74fb249263eb8c12d5c83c
|
data/.travis.yml
CHANGED
@@ -3,7 +3,7 @@ rvm:
|
|
3
3
|
- 2.1.5
|
4
4
|
before_install: gem install bundler
|
5
5
|
gemfile: Gemfile
|
6
|
-
script:
|
6
|
+
script: make mutate
|
7
7
|
notifications:
|
8
8
|
slack:
|
9
9
|
secure: qCcGv1MmryEhPoHzTvZvgSv21UcC7j2Cfq0b0hmQWuYHrHN+jhqjhg7PuElNyr0mk6N1acIcVqOAWpS20ZkG/mipW2RBBXVEc9zVR10pvJnlKDmGKd4Vmj394VgIknn8ciruglw1LoJManf1bV7/Wm4ITMt3zCQqTMGclRUqA0l/dzK2z9zU35cT4v38nTGnoGVrPQx29FvpU3J/h9qC6kGllw3Bkic2nmpFABYOI49LQFF3/vdrbnK3Zo1rudHMV0lNoPg5Ntrbd6XHXUKrBGBcZmGSh3wW/mfYf9Tcft+5MwtCu4b70KnFknx7oFmBlU8JFYg2x5f1xNSIoRkDmLI5/jNDWJ3oLAtYjgY5CdBMlxnhhfnCBmbaxEJhTuscm2sIp+S+4+ggm8x/daIK3BUaBAV5BT8An52BXhQ/F6cdnYiSVn+5lGap/1wF2TWwnN/oVc+JVfATouG9FCygzMekUaji94JMKBtS+QgoLdAE5ufEGBeDONJELRD8Lca1R4uWSg2snf93GWoONca9aJfkIfXj3m+VaoAM9Bq9DGcOXwZESkltE2E+31Fznh5qYCRH1zgtgB0Hx8x7sdaxNQyybvgNS1R0lGnIU/NrUmREcUi5BYEI5YqygBtkTZ7F/nlYQgydKjjHJ6FG3oLc3ggxffE8oAdpuxvlUQ8ZN6o=
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
### HEAD
|
2
2
|
|
3
|
+
### 0.6.0 (25.05.2016)
|
4
|
+
|
5
|
+
* Ability to provide a custom dispatcher to PubSub::Broker PR #12
|
6
|
+
* Add support for projections PR #13
|
7
|
+
* Added prettier message for case of missing #handle_event method. PR #14
|
8
|
+
* Make file to run all the things PR #15
|
9
|
+
|
3
10
|
### 0.5.0 (21.03.2016)
|
4
11
|
|
5
12
|
* Change: Event class refactoring to make default values more explicit PR #11
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# Contributing to RubyEventStore
|
2
|
+
|
3
|
+
Any kind of contribution is welcomed. Here is a few guidelines that we need contributors to follow.
|
4
|
+
|
5
|
+
## Found a bug? Have a question?
|
6
|
+
|
7
|
+
* [Create a new issue](https://github.com/arkency/ruby_event_store/issues/new), assuming one does not already exist.
|
8
|
+
* Clearly describe the issue including steps to reproduce when it is a bug.
|
9
|
+
* If possible provide a Pull Request with failing test case.
|
10
|
+
|
11
|
+
## Getting Started
|
12
|
+
|
13
|
+
* Make sure you have a [GitHub account](https://github.com/signup/free).
|
14
|
+
* [Fork the repository](https://help.github.com/articles/fork-a-repo/) on GitHub.
|
15
|
+
|
16
|
+
## Making Changes
|
17
|
+
|
18
|
+
* Create a feature branch from where you want to base your work.
|
19
|
+
* Do your work. Please try to keep your commits small and focussed.
|
20
|
+
* Make sure you have added the necessary tests for your changes.
|
21
|
+
* Push your changes to a feature branch in your fork of the repository.
|
22
|
+
* Submit a pull request to the RubyEventStore repository.
|
23
|
+
|
24
|
+
# Additional Resources
|
25
|
+
|
26
|
+
* [General GitHub documentation](http://help.github.com/)
|
27
|
+
* [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
|
data/Makefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
install-bundler: ## Install gem dependencies
|
2
|
+
@echo "Installing gem dependencies"
|
3
|
+
@bundle install
|
4
|
+
|
5
|
+
install: install-bundler ## Prepare current development environment
|
6
|
+
|
7
|
+
test: ## Run tests
|
8
|
+
@echo "Running basic tests - beware: this won't guarantee build pass"
|
9
|
+
@bundle exec rspec
|
10
|
+
|
11
|
+
mutate: test ## Run mutation tests
|
12
|
+
@echo "Running mutation tests - only 100% free mutation will be accepted"
|
13
|
+
@bundle exec mutant --include lib --require ruby_event_store --use rspec "RubyEventStore*"
|
14
|
+
|
15
|
+
.PHONY: help
|
16
|
+
|
17
|
+
help:
|
18
|
+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
|
19
|
+
|
20
|
+
.DEFAULT_GOAL := help
|
21
|
+
|
data/README.md
CHANGED
@@ -2,10 +2,19 @@
|
|
2
2
|
[](http://badge.fury.io/rb/ruby_event_store)
|
3
3
|
[](https://codeclimate.com/github/arkency/ruby_event_store)
|
4
4
|
[](https://codeclimate.com/github/arkency/ruby_event_store/coverage)
|
5
|
+
[](https://gitter.im/arkency/rails_event_store?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
5
6
|
|
6
7
|
# RubyEventStore
|
7
8
|
|
8
|
-
A Ruby implementation of an EventStore. It is an integral part of
|
9
|
+
A Ruby implementation of an EventStore. It is an integral part of [rails_event_store](http://github.com/arkency/rails_event_store) gem.
|
10
|
+
|
11
|
+
# Documentation
|
12
|
+
|
13
|
+
All documentation and sample codes are available at [http://railseventstore.arkency.com](http://railseventstore.arkency.com)
|
14
|
+
|
15
|
+
# Contributing
|
16
|
+
|
17
|
+
Check the contribution guide on [CONTRIBUTING.md](https://github.com/arkency/ruby_event_store/blob/master/CONTRIBUTING.md)
|
9
18
|
|
10
19
|
## About
|
11
20
|
|
data/lib/ruby_event_store.rb
CHANGED
@@ -0,0 +1,56 @@
|
|
1
|
+
module RubyEventStore
|
2
|
+
class Projection
|
3
|
+
private_class_method :new
|
4
|
+
|
5
|
+
def self.from_stream(*streams)
|
6
|
+
raise(ArgumentError, "At least one stream must be given") if streams.empty?
|
7
|
+
new(streams)
|
8
|
+
end
|
9
|
+
|
10
|
+
def initialize(streams)
|
11
|
+
@streams = streams
|
12
|
+
@handlers = Hash.new { ->(_, _) {} }
|
13
|
+
@init = -> { Hash.new }
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :streams, :handlers
|
17
|
+
|
18
|
+
def init(handler)
|
19
|
+
@init = handler
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def when(event, handler)
|
24
|
+
@handlers[event] = handler
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def initial_state
|
29
|
+
@init.call
|
30
|
+
end
|
31
|
+
|
32
|
+
def current_state
|
33
|
+
@current_state ||= initial_state
|
34
|
+
end
|
35
|
+
|
36
|
+
def handle_event(event)
|
37
|
+
handlers[event.class].(current_state, event)
|
38
|
+
end
|
39
|
+
|
40
|
+
def handled_events
|
41
|
+
handlers.keys
|
42
|
+
end
|
43
|
+
|
44
|
+
def call(event_store)
|
45
|
+
streams.reduce(initial_state) do |state, stream|
|
46
|
+
event_store.read_stream_events_forward(stream).reduce(state, &method(:transition))
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
def transition(state, event)
|
52
|
+
handlers[event.class].(state, event)
|
53
|
+
state
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module RubyEventStore
|
2
2
|
module PubSub
|
3
3
|
class Broker
|
4
|
+
DEFAULT_DISPATCHER = ->(subscriber, event) { subscriber.handle_event(event) }
|
4
5
|
|
5
|
-
def initialize
|
6
|
+
def initialize(dispatcher = DEFAULT_DISPATCHER)
|
6
7
|
@subscribers = Hash.new {|hsh, key| hsh[key] = [] }
|
7
8
|
@global_subscribers = []
|
9
|
+
@dispatcher = dispatcher
|
8
10
|
end
|
9
11
|
|
10
12
|
def add_subscriber(subscriber, event_types)
|
@@ -19,16 +21,16 @@ module RubyEventStore
|
|
19
21
|
|
20
22
|
def notify_subscribers(event)
|
21
23
|
all_subscribers_for(event.class).each do |subscriber|
|
22
|
-
|
24
|
+
dispatcher.call(subscriber, event)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
28
|
private
|
27
|
-
attr_reader :subscribers
|
29
|
+
attr_reader :subscribers, :dispatcher
|
28
30
|
|
29
31
|
def verify_subscriber(subscriber)
|
30
32
|
raise SubscriberNotExist if subscriber.nil?
|
31
|
-
|
33
|
+
ensure_method_defined(subscriber)
|
32
34
|
end
|
33
35
|
|
34
36
|
def subscribe(subscriber, event_types)
|
@@ -37,9 +39,19 @@ module RubyEventStore
|
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
42
|
+
def ensure_method_defined(subscriber)
|
43
|
+
unless subscriber.methods.include? :handle_event
|
44
|
+
raise MethodNotDefined.new(method_not_defined_message(subscriber))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
40
48
|
def all_subscribers_for(event_type)
|
41
49
|
subscribers[event_type] + @global_subscribers
|
42
50
|
end
|
51
|
+
|
52
|
+
def method_not_defined_message(subscriber)
|
53
|
+
"#handle_event method is not found in #{subscriber.class} subscriber. Are you sure it is a valid subscriber?"
|
54
|
+
end
|
43
55
|
end
|
44
56
|
end
|
45
57
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_event_store
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rybex
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-05-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -92,7 +92,9 @@ files:
|
|
92
92
|
- ".gitignore"
|
93
93
|
- ".travis.yml"
|
94
94
|
- CHANGELOG.md
|
95
|
+
- CONTRIBUTING.md
|
95
96
|
- Gemfile
|
97
|
+
- Makefile
|
96
98
|
- README.md
|
97
99
|
- Rakefile
|
98
100
|
- lib/ruby_event_store.rb
|
@@ -101,6 +103,7 @@ files:
|
|
101
103
|
- lib/ruby_event_store/event.rb
|
102
104
|
- lib/ruby_event_store/facade.rb
|
103
105
|
- lib/ruby_event_store/in_memory_repository.rb
|
106
|
+
- lib/ruby_event_store/projection.rb
|
104
107
|
- lib/ruby_event_store/pub_sub/broker.rb
|
105
108
|
- lib/ruby_event_store/spec/event_repository_lint.rb
|
106
109
|
- lib/ruby_event_store/version.rb
|