nexus_cqrs 0.0.13 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitlab-ci.yml +24 -1
- data/.rspec +1 -0
- data/Gemfile +1 -0
- data/Gemfile.lock +3 -21
- data/README.md +26 -0
- data/lib/nexus_cqrs.rb +2 -0
- data/lib/nexus_cqrs/base_command.rb +1 -1
- data/lib/nexus_cqrs/base_message.rb +28 -0
- data/lib/nexus_cqrs/base_middleware.rb +11 -0
- data/lib/nexus_cqrs/base_query.rb +1 -1
- data/lib/nexus_cqrs/base_query_handler.rb +1 -1
- data/lib/nexus_cqrs/command_bus.rb +13 -7
- data/lib/nexus_cqrs/command_executor.rb +1 -1
- data/lib/nexus_cqrs/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba82d98a3e3c930a35f6d06960be706925bf96db44766686fb2db3460649a792
|
4
|
+
data.tar.gz: 96ecd8dd6f98fb2637cc740d45a52a7c5f488e1f058fb7ff32215d4a7e050a57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d606496e70c6d987723a99b0620b20fc68370c06d7e5d891bb870375d4d16c5dd5c43c761f235e22deeddad2130951d32048ff9089fc9db94a138c96b3b8d050
|
7
|
+
data.tar.gz: 5af5eee683dfa8717038a7fe275eebb11c82b0c2b82bf24962c9083ecc22dca82e666d4324d90e17bae7729a3f999c0e7d2f2267f1e2b4fc28e7758c333cd2c4
|
data/.gitlab-ci.yml
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
image: "ruby:2.7"
|
2
2
|
|
3
|
+
stages:
|
4
|
+
- release
|
5
|
+
- test
|
6
|
+
|
3
7
|
before_script:
|
4
8
|
- sudo apt-get update -qq && sudo apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
|
5
9
|
- ruby -v
|
@@ -13,4 +17,23 @@ rspec:
|
|
13
17
|
|
14
18
|
rubocop:
|
15
19
|
script:
|
16
|
-
- bundle exec rubocop
|
20
|
+
- bundle exec rubocop
|
21
|
+
|
22
|
+
release:
|
23
|
+
stage: release
|
24
|
+
rules:
|
25
|
+
- if: '$CI_COMMIT_TAG'
|
26
|
+
script:
|
27
|
+
- mkdir -p ~/.gem
|
28
|
+
- cp /builds/pub/nexus_cqrs.tmp/RUBYGEMS_CREDENTIALS ~/.gem/credentials
|
29
|
+
- chmod 0600 ~/.gem/credentials
|
30
|
+
- gem update --system
|
31
|
+
- ruby --version
|
32
|
+
- gem env version
|
33
|
+
- sed -i "s/0.1.0/$CI_COMMIT_TAG/g" lib/nexus_cqrs/version.rb
|
34
|
+
- gem build nexus_cqrs.gemspec
|
35
|
+
- gem push nexus_cqrs*.gem
|
36
|
+
artifacts:
|
37
|
+
paths:
|
38
|
+
- gitlab-styles*.gem
|
39
|
+
expire_in: 30 days
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nexus_cqrs (0.0
|
4
|
+
nexus_cqrs (0.1.0)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
@@ -36,17 +36,13 @@ GEM
|
|
36
36
|
railties (>= 3.0.0)
|
37
37
|
i18n (1.8.5)
|
38
38
|
concurrent-ruby (~> 1.0)
|
39
|
+
ibsciss-middleware (0.4.2)
|
39
40
|
loofah (2.6.0)
|
40
41
|
crass (~> 1.0.2)
|
41
42
|
nokogiri (>= 1.5.9)
|
42
43
|
method_source (1.0.0)
|
43
44
|
mini_portile2 (2.4.0)
|
44
45
|
minitest (5.14.1)
|
45
|
-
multi_json (1.15.0)
|
46
|
-
net-scp (3.0.0)
|
47
|
-
net-ssh (>= 2.6.5, < 7.0.0)
|
48
|
-
net-ssh (6.1.0)
|
49
|
-
net-telnet (0.1.1)
|
50
46
|
nokogiri (1.10.10)
|
51
47
|
mini_portile2 (~> 2.4.0)
|
52
48
|
parallel (1.19.2)
|
@@ -79,9 +75,6 @@ GEM
|
|
79
75
|
rspec-expectations (3.9.2)
|
80
76
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
77
|
rspec-support (~> 3.9.0)
|
82
|
-
rspec-its (1.3.0)
|
83
|
-
rspec-core (>= 3.0.0)
|
84
|
-
rspec-expectations (>= 3.0.0)
|
85
78
|
rspec-mocks (3.9.1)
|
86
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
87
80
|
rspec-support (~> 3.9.0)
|
@@ -100,17 +93,6 @@ GEM
|
|
100
93
|
rubocop-shopify (1.0.4)
|
101
94
|
rubocop (>= 0.85, < 0.87)
|
102
95
|
ruby-progressbar (1.10.1)
|
103
|
-
serverspec (2.41.5)
|
104
|
-
multi_json
|
105
|
-
rspec (~> 3.0)
|
106
|
-
rspec-its
|
107
|
-
specinfra (~> 2.72)
|
108
|
-
sfl (2.3)
|
109
|
-
specinfra (2.82.19)
|
110
|
-
net-scp
|
111
|
-
net-ssh (>= 2.7)
|
112
|
-
net-telnet (= 0.1.1)
|
113
|
-
sfl
|
114
96
|
thor (1.0.1)
|
115
97
|
thread_safe (0.3.6)
|
116
98
|
tzinfo (1.2.7)
|
@@ -123,11 +105,11 @@ PLATFORMS
|
|
123
105
|
|
124
106
|
DEPENDENCIES
|
125
107
|
generator_spec
|
108
|
+
ibsciss-middleware
|
126
109
|
nexus_cqrs!
|
127
110
|
rspec
|
128
111
|
rubocop
|
129
112
|
rubocop-shopify (~> 1.0.4)
|
130
|
-
serverspec
|
131
113
|
thread_safe
|
132
114
|
|
133
115
|
BUNDLED WITH
|
data/README.md
CHANGED
@@ -29,6 +29,32 @@ Generators can be used to aide in the creation of Commands and Queries:
|
|
29
29
|
|
30
30
|
Once installed, a CommandBus is required to control the flow of Commands and/or Queries:
|
31
31
|
|
32
|
+
### Middleware
|
33
|
+
|
34
|
+
Middleware can be created by extending the base middleware:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
class MyMiddleware < NexusCqrs::BaseMiddleware
|
38
|
+
def call(command)
|
39
|
+
@next.call(command)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
The above middleware will pass responsibility for execution to the next responder in the chain.
|
45
|
+
|
46
|
+
For more information on writing middleware see: https://github.com/Ibsciss/ruby-middleware
|
47
|
+
|
48
|
+
When creating a bus, middleware can be attached like so:
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
middleware_stack = Middleware::Builder.new do |b|
|
52
|
+
b.use MyMiddleware
|
53
|
+
end
|
54
|
+
|
55
|
+
command_bus = Bus.new(middleware: middleware_stack)
|
56
|
+
```
|
57
|
+
|
32
58
|
## Development
|
33
59
|
|
34
60
|
To contribute to this gem, simple pull the repository, run `bundle install` and run tests:
|
data/lib/nexus_cqrs.rb
CHANGED
@@ -0,0 +1,28 @@
|
|
1
|
+
module NexusCqrs
|
2
|
+
class BaseMessage
|
3
|
+
def set_metadata(key, value)
|
4
|
+
@metadata = {} unless @metadata
|
5
|
+
@metadata[key.to_sym] = value
|
6
|
+
end
|
7
|
+
|
8
|
+
def metadata
|
9
|
+
@metadata || {}
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_h
|
13
|
+
hash = instance_variables.each_with_object({}) do |var, acc|
|
14
|
+
acc[var.to_s[1..-1].to_sym] = instance_variable_get(var)
|
15
|
+
end
|
16
|
+
hash[:metadata] = @metadata || {}
|
17
|
+
hash
|
18
|
+
end
|
19
|
+
|
20
|
+
def policy_class
|
21
|
+
demodularised_class_name + 'Policy'
|
22
|
+
end
|
23
|
+
|
24
|
+
def demodularised_class_name
|
25
|
+
self.class.name.split('::').last
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
require 'thread_safe'
|
2
|
+
require 'middleware'
|
2
3
|
|
3
4
|
module NexusCqrs
|
4
5
|
class CommandBus
|
5
6
|
UnregisteredHandler = Class.new(StandardError)
|
6
7
|
MultipleHandlers = Class.new(StandardError)
|
7
8
|
|
8
|
-
def initialize
|
9
|
+
def initialize(middleware: nil)
|
9
10
|
@handlers =
|
10
11
|
ThreadSafe::Cache.new
|
12
|
+
@middleware = middleware || Middleware::Builder.new
|
11
13
|
end
|
12
14
|
|
13
15
|
def register(klass, handler)
|
@@ -17,19 +19,23 @@ module NexusCqrs
|
|
17
19
|
end
|
18
20
|
|
19
21
|
def call(command)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
.call(command)
|
22
|
+
runner = Middleware::Builder.new
|
23
|
+
runner.use(@middleware)
|
24
|
+
runner.use(->(command_) { handler_for_command(command_).call(command_) })
|
25
|
+
runner.call(command)
|
25
26
|
end
|
26
27
|
|
27
28
|
def registered_handlers
|
28
29
|
handlers
|
29
30
|
end
|
30
31
|
|
32
|
+
attr_reader :handlers
|
33
|
+
|
31
34
|
private
|
32
35
|
|
33
|
-
|
36
|
+
def handler_for_command(command)
|
37
|
+
unregistered_handler = proc { raise UnregisteredHandler, "Missing handler for #{command.class}" }
|
38
|
+
handlers.fetch(command.class, &unregistered_handler)
|
39
|
+
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/nexus_cqrs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_cqrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Lovett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-09-
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -19,6 +19,7 @@ extra_rdoc_files: []
|
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
21
|
- ".gitlab-ci.yml"
|
22
|
+
- ".rspec"
|
22
23
|
- ".rubocop.yml"
|
23
24
|
- CODE_OF_CONDUCT.md
|
24
25
|
- Gemfile
|
@@ -38,6 +39,8 @@ files:
|
|
38
39
|
- lib/nexus_cqrs.rb
|
39
40
|
- lib/nexus_cqrs/base_command.rb
|
40
41
|
- lib/nexus_cqrs/base_command_handler.rb
|
42
|
+
- lib/nexus_cqrs/base_message.rb
|
43
|
+
- lib/nexus_cqrs/base_middleware.rb
|
41
44
|
- lib/nexus_cqrs/base_query.rb
|
42
45
|
- lib/nexus_cqrs/base_query_handler.rb
|
43
46
|
- lib/nexus_cqrs/command_bus.rb
|
@@ -63,7 +66,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
66
|
- !ruby/object:Gem::Version
|
64
67
|
version: '0'
|
65
68
|
requirements: []
|
66
|
-
rubygems_version: 3.1.
|
69
|
+
rubygems_version: 3.1.4
|
67
70
|
signing_key:
|
68
71
|
specification_version: 4
|
69
72
|
summary: Core package for the nexus cqrs gem
|