nexus_cqrs 0.0.10 → 0.1.1
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 +6 -21
- data/README.md +31 -1
- data/lib/generators/nexus_cqrs/command_generator.rb +1 -1
- data/lib/generators/nexus_cqrs/query_generator.rb +1 -1
- 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/helpers.rb +1 -2
- data/lib/nexus_cqrs/version.rb +1 -1
- data/nexus_cqrs.gemspec +3 -0
- metadata +49 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52292e7da4d25c422ec78ea425803320ce2d482748a07e64cf46935a9b529fba
|
4
|
+
data.tar.gz: f6f6ea685f1c98e1d9396735c3bd605823d3fe20807b0d9041c2924501a93346
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86c7633be2217afc934de294f1a01930c417f19d7cc47daa3354a14baae9f0700ab3dbd4864c7059dfe5a9569225c9c1ad2e36b9a3fe93113b10ad6cd8bb4da1
|
7
|
+
data.tar.gz: a45c022c39ad8dabbc1fb86910e3effd7c58bfa1e049dab0b950650b88fc9b31e357fcea0d272454df7efc9ee5203af5d927ffde6b4454ee091b97d5f9291d7b
|
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
|
+
- nexus_cqrs*.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,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nexus_cqrs (0.0
|
4
|
+
nexus_cqrs (0.1.0)
|
5
|
+
generator_spec
|
6
|
+
ibsciss-middleware
|
7
|
+
thread_safe
|
5
8
|
|
6
9
|
GEM
|
7
10
|
remote: https://rubygems.org/
|
@@ -36,17 +39,13 @@ GEM
|
|
36
39
|
railties (>= 3.0.0)
|
37
40
|
i18n (1.8.5)
|
38
41
|
concurrent-ruby (~> 1.0)
|
42
|
+
ibsciss-middleware (0.4.2)
|
39
43
|
loofah (2.6.0)
|
40
44
|
crass (~> 1.0.2)
|
41
45
|
nokogiri (>= 1.5.9)
|
42
46
|
method_source (1.0.0)
|
43
47
|
mini_portile2 (2.4.0)
|
44
48
|
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
49
|
nokogiri (1.10.10)
|
51
50
|
mini_portile2 (~> 2.4.0)
|
52
51
|
parallel (1.19.2)
|
@@ -79,9 +78,6 @@ GEM
|
|
79
78
|
rspec-expectations (3.9.2)
|
80
79
|
diff-lcs (>= 1.2.0, < 2.0)
|
81
80
|
rspec-support (~> 3.9.0)
|
82
|
-
rspec-its (1.3.0)
|
83
|
-
rspec-core (>= 3.0.0)
|
84
|
-
rspec-expectations (>= 3.0.0)
|
85
81
|
rspec-mocks (3.9.1)
|
86
82
|
diff-lcs (>= 1.2.0, < 2.0)
|
87
83
|
rspec-support (~> 3.9.0)
|
@@ -100,17 +96,6 @@ GEM
|
|
100
96
|
rubocop-shopify (1.0.4)
|
101
97
|
rubocop (>= 0.85, < 0.87)
|
102
98
|
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
99
|
thor (1.0.1)
|
115
100
|
thread_safe (0.3.6)
|
116
101
|
tzinfo (1.2.7)
|
@@ -123,11 +108,11 @@ PLATFORMS
|
|
123
108
|
|
124
109
|
DEPENDENCIES
|
125
110
|
generator_spec
|
111
|
+
ibsciss-middleware
|
126
112
|
nexus_cqrs!
|
127
113
|
rspec
|
128
114
|
rubocop
|
129
115
|
rubocop-shopify (~> 1.0.4)
|
130
|
-
serverspec
|
131
116
|
thread_safe
|
132
117
|
|
133
118
|
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:
|
@@ -36,4 +62,8 @@ To contribute to this gem, simple pull the repository, run `bundle install` and
|
|
36
62
|
```shell script
|
37
63
|
bundle exec rspec
|
38
64
|
bundle exec rubocop
|
39
|
-
```
|
65
|
+
```
|
66
|
+
|
67
|
+
## Releasing
|
68
|
+
|
69
|
+
The release process is tied to the git tags. Simply creating a new tag and pushing will trigger a new release to reubygems.
|
@@ -22,7 +22,7 @@ module NexusCqrs
|
|
22
22
|
template('register_cqrs_handlers.rb', handler_config)
|
23
23
|
end
|
24
24
|
|
25
|
-
code_to_inject = "$COMMAND_EXECUTOR.register_command(#{full_name}, #{full_name}Handler)"
|
25
|
+
code_to_inject = "$COMMAND_EXECUTOR.register_command(#{full_name}, #{full_name}Handler.new)\n"
|
26
26
|
|
27
27
|
inject_into_file(handler_config, code_to_inject, after: "# Register Commands\n")
|
28
28
|
end
|
@@ -22,7 +22,7 @@ module NexusCqrs
|
|
22
22
|
template('register_cqrs_handlers.rb', handler_config)
|
23
23
|
end
|
24
24
|
|
25
|
-
code_to_inject = "$QUERY_EXECUTOR.register_command(#{full_name}, #{full_name}Handler)"
|
25
|
+
code_to_inject = "$QUERY_EXECUTOR.register_command(#{full_name}, #{full_name}Handler.new)\n"
|
26
26
|
|
27
27
|
inject_into_file(handler_config, code_to_inject, after: "# Register Queries\n")
|
28
28
|
end
|
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/helpers.rb
CHANGED
data/lib/nexus_cqrs/version.rb
CHANGED
data/nexus_cqrs.gemspec
CHANGED
@@ -17,4 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.bindir = 'exe'
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ['lib']
|
20
|
+
spec.add_dependency('generator_spec')
|
21
|
+
spec.add_dependency('thread_safe')
|
22
|
+
spec.add_dependency('ibsciss-middleware')
|
20
23
|
end
|
metadata
CHANGED
@@ -1,15 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexus_cqrs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.1.1
|
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-
|
12
|
-
dependencies:
|
11
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: generator_spec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thread_safe
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: ibsciss-middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
13
55
|
description:
|
14
56
|
email:
|
15
57
|
- dean.lovett@nexusmods.com
|
@@ -19,6 +61,7 @@ extra_rdoc_files: []
|
|
19
61
|
files:
|
20
62
|
- ".gitignore"
|
21
63
|
- ".gitlab-ci.yml"
|
64
|
+
- ".rspec"
|
22
65
|
- ".rubocop.yml"
|
23
66
|
- CODE_OF_CONDUCT.md
|
24
67
|
- Gemfile
|
@@ -38,6 +81,8 @@ files:
|
|
38
81
|
- lib/nexus_cqrs.rb
|
39
82
|
- lib/nexus_cqrs/base_command.rb
|
40
83
|
- lib/nexus_cqrs/base_command_handler.rb
|
84
|
+
- lib/nexus_cqrs/base_message.rb
|
85
|
+
- lib/nexus_cqrs/base_middleware.rb
|
41
86
|
- lib/nexus_cqrs/base_query.rb
|
42
87
|
- lib/nexus_cqrs/base_query_handler.rb
|
43
88
|
- lib/nexus_cqrs/command_bus.rb
|
@@ -63,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
108
|
- !ruby/object:Gem::Version
|
64
109
|
version: '0'
|
65
110
|
requirements: []
|
66
|
-
rubygems_version: 3.1.
|
111
|
+
rubygems_version: 3.1.4
|
67
112
|
signing_key:
|
68
113
|
specification_version: 4
|
69
114
|
summary: Core package for the nexus cqrs gem
|