cqrs-core 0.1.2 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/cqrs-core.gemspec +2 -1
- data/lib/cqrs/base_command.rb +5 -0
- data/lib/cqrs/base_command_handler.rb +4 -0
- data/lib/cqrs/base_query.rb +4 -0
- data/lib/cqrs/base_query_handler.rb +4 -0
- data/lib/cqrs/command_bus.rb +27 -0
- data/lib/cqrs/command_executor.rb +18 -0
- data/lib/cqrs/core/version.rb +1 -1
- data/lib/cqrs/helpers.rb +18 -0
- metadata +26 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c48df792d3739e54a1cd70358f7af03ab2a9d5f1ff20759e0b61cdee8a6bf116
|
4
|
+
data.tar.gz: e1c9f5d8666b09118fdccc6e7c08fcc687bd411c157def85df0e750e0b52ff9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18943718a56983d5ab8da3a1839234cf607d02a3da6f92aeb98da55a477d8b063b3eb181f0dedb48300d25bbe712cbdb2f70615ff662d766023f467b030202b2
|
7
|
+
data.tar.gz: 891c28156a57eb0b59bba99cf4b7550858067bc245baf5ed5380317fdfd245599e515daaf9e7c842a6fa85425694de779362c652b14da69c4ffebc962fb16a85
|
data/cqrs-core.gemspec
CHANGED
@@ -18,5 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rails", "~> 5"
|
22
23
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'thread_safe'
|
2
|
+
|
3
|
+
module Cqrs
|
4
|
+
class CommandBus
|
5
|
+
UnregisteredHandler = Class.new(StandardError)
|
6
|
+
MultipleHandlers = Class.new(StandardError)
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@handlers =
|
10
|
+
ThreadSafe::Cache.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def register(klass, handler)
|
14
|
+
raise MultipleHandlers.new("Multiple handlers not allowed for #{klass}") if handlers[klass]
|
15
|
+
handlers[klass] = handler
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(command)
|
19
|
+
handlers
|
20
|
+
.fetch(command.class) { raise UnregisteredHandler.new("Missing handler for #{command.class}") }
|
21
|
+
.(command)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
attr_reader :handlers
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Cqrs
|
2
|
+
class CommandExecutor
|
3
|
+
def initialize
|
4
|
+
@bus = CommandBus.new
|
5
|
+
|
6
|
+
register_commands
|
7
|
+
end
|
8
|
+
|
9
|
+
def execute(command)
|
10
|
+
@bus.(command)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
def register_commands
|
15
|
+
# TODO, Register Commands/Queries
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/cqrs/core/version.rb
CHANGED
data/lib/cqrs/helpers.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Cqrs
|
2
|
+
module Helpers
|
3
|
+
# Executes a CQRS Command
|
4
|
+
def execute(command)
|
5
|
+
command_executor.execute(command)
|
6
|
+
end
|
7
|
+
|
8
|
+
# Executes a CQRS Query
|
9
|
+
def query(query)
|
10
|
+
command_executor.execute(query)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Provide access to the CQRS executor
|
14
|
+
def command_executor
|
15
|
+
@command_executor ||= NexusCqrs::CommandExecutor.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cqrs-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dean
|
@@ -11,19 +11,33 @@ cert_chain: []
|
|
11
11
|
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
20
|
-
type: :
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
27
41
|
description:
|
28
42
|
email:
|
29
43
|
- dean.lovett@nexusmods.com
|
@@ -39,8 +53,15 @@ files:
|
|
39
53
|
- bin/console
|
40
54
|
- bin/setup
|
41
55
|
- cqrs-core.gemspec
|
56
|
+
- lib/cqrs/base_command.rb
|
57
|
+
- lib/cqrs/base_command_handler.rb
|
58
|
+
- lib/cqrs/base_query.rb
|
59
|
+
- lib/cqrs/base_query_handler.rb
|
60
|
+
- lib/cqrs/command_bus.rb
|
61
|
+
- lib/cqrs/command_executor.rb
|
42
62
|
- lib/cqrs/core.rb
|
43
63
|
- lib/cqrs/core/version.rb
|
64
|
+
- lib/cqrs/helpers.rb
|
44
65
|
homepage:
|
45
66
|
licenses: []
|
46
67
|
metadata: {}
|