cqrs-core 0.1.5 → 0.1.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- 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 +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 137060e63458ed068457d7f25bb6d589419866c33b16399d363a7a9bb0ee5029
|
4
|
+
data.tar.gz: 2a8411c509d1304d1f9242ffa89aa823ef8bd91a8354880d00ad1dbdca5ae4b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ca37df9b52a0ebad59ac3010a119ce163044dbebc8011bc1b594d9ef1d07b63963e0a09807e9c680202efe15a0458a73a5760995396e9b31a7d634b070a8be58
|
7
|
+
data.tar.gz: b0d19dee22f4d3cafe9e6d4b3ec4f61790329c6b8a5e247731ad0d9828d5f6874084c7f4f06f766b3332e41d7f59570acaed0abefca3884110d733b8640995ae
|
@@ -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.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dean
|
@@ -53,8 +53,15 @@ files:
|
|
53
53
|
- bin/console
|
54
54
|
- bin/setup
|
55
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
|
56
62
|
- lib/cqrs/core.rb
|
57
63
|
- lib/cqrs/core/version.rb
|
64
|
+
- lib/cqrs/helpers.rb
|
58
65
|
homepage:
|
59
66
|
licenses: []
|
60
67
|
metadata: {}
|