nexus_cqrs 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/Gemfile.lock +1 -1
- data/lib/nexus_cqrs/command_executor.rb +22 -15
- data/lib/nexus_cqrs/version.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 967dfb16241304d1d0f2233b23e3410b87abff47ec4a916569101a53e4b963c5
|
4
|
+
data.tar.gz: d528d7da45c96cae5fe8a403116e3f9c8abc83c2842dbd165dfa5c3267a81e1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1f407d669371be6e3fd4f9ad4e55f92678b6fc82825b1dba6f5bf4a1dabb070c79005bdf37a114dd2461f6b99d7213daf777894d04f3337daf4a8255a74fa2f6
|
7
|
+
data.tar.gz: 6d31c90bff990bd92f7aeb9ffcf289d1fe47bb5fd987d47f14fb12e7a7d9baa0571f731a466dff569999976a370c7028a6380c8f4423a5798ecc1063f8847029
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,42 +1,49 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
|
2
3
|
module NexusCqrs
|
3
4
|
class CommandExecutor
|
4
5
|
# @param [NexusCqrs::CommandBus] command_bus
|
5
6
|
def initialize(command_bus)
|
6
7
|
@bus = command_bus
|
8
|
+
@logger = logger
|
9
|
+
end
|
10
|
+
|
11
|
+
# Get logger instance depending on runtime environment.
|
12
|
+
def logger
|
13
|
+
defined?(Rails) && defined?(Rails.logger) ? Rails.logger : Logger.new(STDOUT)
|
7
14
|
end
|
8
15
|
|
9
16
|
def autoregister(base_class, dir = 'app/domain/commands', ignore_strings = ['.rb', 'app/domain/'])
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
+
if defined?(Rails)
|
18
|
+
# Iterate over the directory passed and find all ruby files.
|
19
|
+
Dir["#{dir}/**/*.rb"].each do |file|
|
20
|
+
# Constantize class name to constant to force rails to autoload this class.
|
21
|
+
# Note that autoloading won't work when testing this gem standalone, but this does trigger the necessary
|
22
|
+
# loading when in a rails environment.
|
23
|
+
ignore_strings.each do |i|
|
24
|
+
file.slice!(i)
|
25
|
+
end
|
26
|
+
@logger.debug { "Attempting constantize of #{file}" }
|
17
27
|
file.camelize.constantize
|
18
|
-
rescue NameError
|
19
|
-
|
28
|
+
rescue NameError => e
|
29
|
+
@logger.warn { "Failed autoregister #{file.camelize}, received NameError: #{e}" }
|
20
30
|
end
|
21
31
|
end
|
22
32
|
|
23
33
|
ObjectSpace.each_object(Class).select { |klass| klass < base_class }.each do |c|
|
34
|
+
@logger.debug { "Attempting auto registration of #{c}" }
|
24
35
|
handler_name = (c.to_s + "Handler")
|
25
36
|
begin
|
26
37
|
handler = handler_name.constantize.new
|
27
38
|
rescue NameError
|
28
|
-
|
29
|
-
"WARN: A command `#{c}` tried to autoregister `#{handler_name}` but the class was not found"
|
30
|
-
)
|
39
|
+
@logger.warn { "Command `#{c}` tried to autoregister `#{handler_name}` but the class was not found" }
|
31
40
|
next
|
32
41
|
end
|
33
42
|
|
34
43
|
if handler.respond_to?(:call)
|
35
44
|
register_command(c, handler)
|
36
45
|
else
|
37
|
-
|
38
|
-
"WARN: A command `#{c}` tried to autoregister `#{handler_name}` but `call` method did not exist"
|
39
|
-
)
|
46
|
+
@logger.warn { "Command `#{c}` tried to autoregister `#{handler_name}` but `call` method did not exist" }
|
40
47
|
end
|
41
48
|
end
|
42
49
|
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.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dean Lovett
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-11-
|
11
|
+
date: 2021-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: generator_spec
|