cqrs-core 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa36a318f9c9dbd3e9cf6f8ff1338904c387c649c8b3b8339bfd699c6459571e
4
- data.tar.gz: 4e2f64b545353cf2c032a7eaa0e51eded8e7419f4af4f1c23e12219b19e6c46e
3
+ metadata.gz: 137060e63458ed068457d7f25bb6d589419866c33b16399d363a7a9bb0ee5029
4
+ data.tar.gz: 2a8411c509d1304d1f9242ffa89aa823ef8bd91a8354880d00ad1dbdca5ae4b5
5
5
  SHA512:
6
- metadata.gz: 61d6af25c6f0e347566be18c341cf91240fa469c50f76512491b77b1233eb3bddd0475cb59782fde87926fa81d65eb6001b219c331d4b11afacfd8259faa4bfa
7
- data.tar.gz: f4cc8c362491b6aba91b782d952f37630271ef9decdf047235ca6e102d02292f6a8ca2643a3215531901cbffd27f70f179ad4b5de53a36ad34616d7079d276e7
6
+ metadata.gz: ca37df9b52a0ebad59ac3010a119ce163044dbebc8011bc1b594d9ef1d07b63963e0a09807e9c680202efe15a0458a73a5760995396e9b31a7d634b070a8be58
7
+ data.tar.gz: b0d19dee22f4d3cafe9e6d4b3ec4f61790329c6b8a5e247731ad0d9828d5f6874084c7f4f06f766b3332e41d7f59570acaed0abefca3884110d733b8640995ae
@@ -0,0 +1,5 @@
1
+ module Cqrs
2
+ class BaseCommand
3
+
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ module Cqrs
2
+ class BaseCommandHandler
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cqrs
2
+ class BaseQuery
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Cqrs
2
+ class BaseQueryHandler
3
+ end
4
+ 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
@@ -1,5 +1,5 @@
1
1
  module Cqrs
2
2
  module Core
3
- VERSION = "0.1.5"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
@@ -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.5
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: {}