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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a8507c881ef6ee7b0d899e87139af7cc7e85d1a96e49aa73294f21f4d2f1421
4
- data.tar.gz: f02d250460fe4ea0bb5d67a9f458a7f5390301992490db27bd0bc8cce8674919
3
+ metadata.gz: 967dfb16241304d1d0f2233b23e3410b87abff47ec4a916569101a53e4b963c5
4
+ data.tar.gz: d528d7da45c96cae5fe8a403116e3f9c8abc83c2842dbd165dfa5c3267a81e1d
5
5
  SHA512:
6
- metadata.gz: 1017532021ac25aeae7003d8db46dbedda5207231afcc26dab93be66cd1ff2d965a3bb5a5915ccd0c52b420eff4706a483c05ff4075ae784d1295421d93f980b
7
- data.tar.gz: ba0f68f56bf7e46fba9998cd94ed8f09c6536b2301408df3277a4825f395d5b4f857094043fceee152b0e4a3bffe50ed4186c0c470575487446ea2844e8bbeef
6
+ metadata.gz: 1f407d669371be6e3fd4f9ad4e55f92678b6fc82825b1dba6f5bf4a1dabb070c79005bdf37a114dd2461f6b99d7213daf777894d04f3337daf4a8255a74fa2f6
7
+ data.tar.gz: 6d31c90bff990bd92f7aeb9ffcf289d1fe47bb5fd987d47f14fb12e7a7d9baa0571f731a466dff569999976a370c7028a6380c8f4423a5798ecc1063f8847029
data/.gitignore CHANGED
@@ -11,3 +11,6 @@
11
11
  *.gem
12
12
 
13
13
  results/rubocop.html
14
+
15
+ # Ignore IDE configuration
16
+ nexus_cqrs.iml
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- nexus_cqrs (0.4.0)
4
+ nexus_cqrs (0.1.0)
5
5
  generator_spec
6
6
  ibsciss-middleware
7
7
  pundit
@@ -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
- # Iterate over the director passed and find all ruby files, removing unwanted parts of the string.
11
- Dir["#{dir}/*.rb"].each do |file|
12
- ignore_strings.each do |i|
13
- file.slice!(i)
14
- end
15
- begin
16
- # Constantize class name to constant to force rails to autoload this class
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
- puts "WARN: Tried to autoregister #{file.camelize} but class could not be found"
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
- Rails.logger.error(
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
- Rails.logger.error(
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
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusCqrs
3
- VERSION = '0.4.0'
3
+ # Leave this as 0.4.2 in order for CI process to replace with the tagged version.
4
+ VERSION = '0.4.2'
4
5
  end
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.0
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-13 00:00:00.000000000 Z
11
+ date: 2021-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: generator_spec