nexus_cqrs 0.0.4 → 0.0.9

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: a0ab24d08b1c4793fef6e3834988672a80f16ebb82d6dbda3d5541c924b8c831
4
- data.tar.gz: ba846c3ce5ca8ca11254ad1521fe89498bed086f3fe1728bc8712343e7352962
3
+ metadata.gz: a4dd646c794131960d2d27fb221171e28291c2f09b49e054143d7e95f535b507
4
+ data.tar.gz: b59b9059f4c2c040ea7df8a6432fa256a925750aa725583567046641faa1d7bf
5
5
  SHA512:
6
- metadata.gz: 94e1db49bdbe1d8a03e4341d95d88c4abd42c9c38be178ad85f813095dded808fa9a76b51b32a95d40886666d9208d2f3f74ce21936e8dda8b48b7fe34a87dee
7
- data.tar.gz: f560cb815379e847dd6cb347346d0eefdefda8234b8aa0ae146114b85be4109af81f6436e65e699a2a51da8219e7baa0dcebd5758ced123a54e47a44c7006a46
6
+ metadata.gz: 856916ff055be3508b09832ff4512bb483089561e0439f8a24b58699a88034b6f2cfac9d6dda641022d7bae62305ab760d474257c1136282b5b1ea820cea5600
7
+ data.tar.gz: b4592c8cfb3108e11329d6501257efc6732cb5bc407336cacb5d6590250351c333836e12f06e81961cbe1200dcab8cd5c2e17302958e0f26bbad3f37fc191d1f
data/.gitignore CHANGED
@@ -7,5 +7,5 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /.gem
10
-
10
+ /spec/lib/tmp
11
11
  *.gem
@@ -0,0 +1,16 @@
1
+ image: "ruby:2.7"
2
+
3
+ before_script:
4
+ - sudo apt-get update -qq && sudo apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
5
+ - ruby -v
6
+ - which ruby
7
+ - gem install bundler --no-document
8
+ - bundle install --jobs $(nproc) "${FLAGS[@]}"
9
+
10
+ rspec:
11
+ script:
12
+ - bundle exec rspec
13
+
14
+ rubocop:
15
+ script:
16
+ - bundle exec rubocop
@@ -0,0 +1,11 @@
1
+ inherit_gem:
2
+ rubocop-shopify: rubocop.yml
3
+
4
+ AllCops:
5
+ Exclude:
6
+ - 'lib/generators/nexus_cqrs/templates/**/*.rb'
7
+
8
+ Style/GlobalVars:
9
+ Enabled: false
10
+ Style/FrozenStringLiteralComment:
11
+ Enabled: false
data/Gemfile CHANGED
@@ -1,6 +1,11 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in cqrs-core.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake", "~> 12.0"
6
+ gem 'rubocop'
7
+ gem 'rubocop-shopify', "~> 1.0.4", require: false
8
+
9
+ gem 'rspec'
10
+ gem "generator_spec"
11
+ gem 'thread_safe'
@@ -0,0 +1,134 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nexus_cqrs (0.0.8)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ actionpack (6.0.3.2)
10
+ actionview (= 6.0.3.2)
11
+ activesupport (= 6.0.3.2)
12
+ rack (~> 2.0, >= 2.0.8)
13
+ rack-test (>= 0.6.3)
14
+ rails-dom-testing (~> 2.0)
15
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
16
+ actionview (6.0.3.2)
17
+ activesupport (= 6.0.3.2)
18
+ builder (~> 3.1)
19
+ erubi (~> 1.4)
20
+ rails-dom-testing (~> 2.0)
21
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
22
+ activesupport (6.0.3.2)
23
+ concurrent-ruby (~> 1.0, >= 1.0.2)
24
+ i18n (>= 0.7, < 2)
25
+ minitest (~> 5.1)
26
+ tzinfo (~> 1.1)
27
+ zeitwerk (~> 2.2, >= 2.2.2)
28
+ ast (2.4.1)
29
+ builder (3.2.4)
30
+ concurrent-ruby (1.1.7)
31
+ crass (1.0.6)
32
+ diff-lcs (1.4.4)
33
+ erubi (1.9.0)
34
+ generator_spec (0.9.4)
35
+ activesupport (>= 3.0.0)
36
+ railties (>= 3.0.0)
37
+ i18n (1.8.5)
38
+ concurrent-ruby (~> 1.0)
39
+ loofah (2.6.0)
40
+ crass (~> 1.0.2)
41
+ nokogiri (>= 1.5.9)
42
+ method_source (1.0.0)
43
+ mini_portile2 (2.4.0)
44
+ minitest (5.14.1)
45
+ multi_json (1.15.0)
46
+ net-scp (3.0.0)
47
+ net-ssh (>= 2.6.5, < 7.0.0)
48
+ net-ssh (6.1.0)
49
+ net-telnet (0.1.1)
50
+ nokogiri (1.10.10)
51
+ mini_portile2 (~> 2.4.0)
52
+ parallel (1.19.2)
53
+ parser (2.7.1.4)
54
+ ast (~> 2.4.1)
55
+ rack (2.2.3)
56
+ rack-test (1.1.0)
57
+ rack (>= 1.0, < 3)
58
+ rails-dom-testing (2.0.3)
59
+ activesupport (>= 4.2.0)
60
+ nokogiri (>= 1.6)
61
+ rails-html-sanitizer (1.3.0)
62
+ loofah (~> 2.3)
63
+ railties (6.0.3.2)
64
+ actionpack (= 6.0.3.2)
65
+ activesupport (= 6.0.3.2)
66
+ method_source
67
+ rake (>= 0.8.7)
68
+ thor (>= 0.20.3, < 2.0)
69
+ rainbow (3.0.0)
70
+ rake (13.0.1)
71
+ regexp_parser (1.7.1)
72
+ rexml (3.2.4)
73
+ rspec (3.9.0)
74
+ rspec-core (~> 3.9.0)
75
+ rspec-expectations (~> 3.9.0)
76
+ rspec-mocks (~> 3.9.0)
77
+ rspec-core (3.9.2)
78
+ rspec-support (~> 3.9.3)
79
+ rspec-expectations (3.9.2)
80
+ diff-lcs (>= 1.2.0, < 2.0)
81
+ rspec-support (~> 3.9.0)
82
+ rspec-its (1.3.0)
83
+ rspec-core (>= 3.0.0)
84
+ rspec-expectations (>= 3.0.0)
85
+ rspec-mocks (3.9.1)
86
+ diff-lcs (>= 1.2.0, < 2.0)
87
+ rspec-support (~> 3.9.0)
88
+ rspec-support (3.9.3)
89
+ rubocop (0.86.0)
90
+ parallel (~> 1.10)
91
+ parser (>= 2.7.0.1)
92
+ rainbow (>= 2.2.2, < 4.0)
93
+ regexp_parser (>= 1.7)
94
+ rexml
95
+ rubocop-ast (>= 0.0.3, < 1.0)
96
+ ruby-progressbar (~> 1.7)
97
+ unicode-display_width (>= 1.4.0, < 2.0)
98
+ rubocop-ast (0.3.0)
99
+ parser (>= 2.7.1.4)
100
+ rubocop-shopify (1.0.4)
101
+ rubocop (>= 0.85, < 0.87)
102
+ ruby-progressbar (1.10.1)
103
+ serverspec (2.41.5)
104
+ multi_json
105
+ rspec (~> 3.0)
106
+ rspec-its
107
+ specinfra (~> 2.72)
108
+ sfl (2.3)
109
+ specinfra (2.82.19)
110
+ net-scp
111
+ net-ssh (>= 2.7)
112
+ net-telnet (= 0.1.1)
113
+ sfl
114
+ thor (1.0.1)
115
+ thread_safe (0.3.6)
116
+ tzinfo (1.2.7)
117
+ thread_safe (~> 0.1)
118
+ unicode-display_width (1.7.0)
119
+ zeitwerk (2.4.0)
120
+
121
+ PLATFORMS
122
+ ruby
123
+
124
+ DEPENDENCIES
125
+ generator_spec
126
+ nexus_cqrs!
127
+ rspec
128
+ rubocop
129
+ rubocop-shopify (~> 1.0.4)
130
+ serverspec
131
+ thread_safe
132
+
133
+ BUNDLED WITH
134
+ 2.1.4
data/README.md CHANGED
@@ -29,3 +29,11 @@ Generators can be used to aide in the creation of Commands and Queries:
29
29
 
30
30
  Once installed, a CommandBus is required to control the flow of Commands and/or Queries:
31
31
 
32
+ ## Development
33
+
34
+ To contribute to this gem, simple pull the repository, run `bundle install` and run tests:
35
+
36
+ ```shell script
37
+ bundle exec rspec
38
+ bundle exec rubocop
39
+ ```
data/Rakefile CHANGED
@@ -1,2 +1,3 @@
1
1
  require "bundler/gem_tasks"
2
- task :default => :spec
2
+ require 'bundler/gem_tasks'
3
+ task(default: :spec)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "cqrs/core"
3
+ require 'bundler/setup'
4
+ require 'cqrs/core'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cqrs/core"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start(__FILE__)
@@ -5,18 +5,26 @@ module NexusCqrs
5
5
  source_root File.expand_path('templates', __dir__)
6
6
 
7
7
  def copy_command_file
8
- template "command.rb", "app/domain/commands/#{file_name}.rb"
9
- template "command_handler.rb", "app/domain/commands/#{file_name}_handler.rb"
8
+ file_path = class_name.underscore
9
+
10
+ template('command.rb', "app/domain/commands/#{file_path}.rb")
11
+ template('command_handler.rb', "app/domain/commands/#{file_path}_handler.rb")
12
+
13
+ register_command(class_name)
10
14
  end
11
15
 
12
- def register_command
13
- handler_config = "config/initializers/register_cqrs_handlers.rb"
16
+ private
17
+
18
+ def register_command(full_name)
19
+ handler_config = 'config/initializers/register_cqrs_handlers.rb'
14
20
 
15
21
  unless File.exist?('config/initializers/register_cqrs_handlers.rb')
16
- template "register_cqrs_handlers.rb", handler_config
22
+ template('register_cqrs_handlers.rb', handler_config)
17
23
  end
18
24
 
19
- inject_into_file handler_config, " do_stuff(foo)\n"
25
+ code_to_inject = "$COMMAND_EXECUTOR.register_command(#{full_name}, #{full_name}Handler)"
26
+
27
+ inject_into_file(handler_config, code_to_inject, after: "# Register Commands\n")
20
28
  end
21
29
  end
22
30
  end
@@ -5,8 +5,26 @@ module NexusCqrs
5
5
  source_root File.expand_path('templates', __dir__)
6
6
 
7
7
  def copy_query_file
8
- template "query.rb", "app/domain/queries/#{file_name}.rb"
9
- template "query_handler.rb", "app/domain/queries/#{file_name}_handler.rb"
8
+ file_path = class_name.underscore
9
+
10
+ template('query.rb', "app/domain/queries/#{file_path}.rb")
11
+ template('query_handler.rb', "app/domain/queries/#{file_path}_handler.rb")
12
+
13
+ register_query(class_name)
14
+ end
15
+
16
+ private
17
+
18
+ def register_query(full_name)
19
+ handler_config = 'config/initializers/register_cqrs_handlers.rb'
20
+
21
+ unless File.exist?('config/initializers/register_cqrs_handlers.rb')
22
+ template('register_cqrs_handlers.rb', handler_config)
23
+ end
24
+
25
+ code_to_inject = "$QUERY_EXECUTOR.register_command(#{full_name}, #{full_name}Handler)"
26
+
27
+ inject_into_file(handler_config, code_to_inject, after: "# Register Queries\n")
10
28
  end
11
29
  end
12
30
  end
@@ -1,4 +1,9 @@
1
1
  command_bus = NexusCqrs::CommandBus.new
2
2
  query_bus = NexusCqrs::CommandBus.new
3
3
 
4
- $CQRS_EXECUTOR = NexusCqrs::CommandExecutor.new command_bus
4
+ $COMMAND_EXECUTOR = NexusCqrs::CommandExecutor.new command_bus
5
+ $QUERY_EXECUTOR = NexusCqrs::CommandExecutor.new query_bus
6
+
7
+ # Register Queries
8
+
9
+ # Register Commands
@@ -8,4 +8,4 @@ require 'nexus_cqrs/helpers'
8
8
 
9
9
  module NexusCqrs
10
10
  class Error < StandardError; end
11
- end
11
+ end
@@ -1,5 +1,4 @@
1
1
  module NexusCqrs
2
2
  class BaseCommand
3
-
4
3
  end
5
- end
4
+ end
@@ -1,4 +1,6 @@
1
1
  module NexusCqrs
2
2
  class BaseCommandHandler
3
+ def call(command)
4
+ end
3
5
  end
4
- end
6
+ end
@@ -1,4 +1,4 @@
1
1
  module NexusCqrs
2
2
  class BaseQuery
3
3
  end
4
- end
4
+ end
@@ -1,4 +1,6 @@
1
1
  module NexusCqrs
2
2
  class BaseQueryHandler
3
+ def call(command)
4
+ end
3
5
  end
4
- end
6
+ end
@@ -7,21 +7,29 @@ module NexusCqrs
7
7
 
8
8
  def initialize
9
9
  @handlers =
10
- ThreadSafe::Cache.new
10
+ ThreadSafe::Cache.new
11
11
  end
12
12
 
13
13
  def register(klass, handler)
14
- raise MultipleHandlers.new("Multiple handlers not allowed for #{klass}") if handlers[klass]
14
+ raise MultipleHandlers, "Multiple handlers not allowed for #{klass}" if handlers[klass]
15
+
15
16
  handlers[klass] = handler
16
17
  end
17
18
 
18
19
  def call(command)
20
+ unregistered_handler = proc { raise UnregisteredHandler, "Missing handler for #{command.class}" }
21
+
22
+ handlers
23
+ .fetch(command.class, &unregistered_handler)
24
+ .call(command)
25
+ end
26
+
27
+ def registered_handlers
19
28
  handlers
20
- .fetch(command.class) { raise UnregisteredHandler.new("Missing handler for #{command.class}") }
21
- .(command)
22
29
  end
23
30
 
24
31
  private
32
+
25
33
  attr_reader :handlers
26
34
  end
27
- end
35
+ end
@@ -7,16 +7,18 @@ module NexusCqrs
7
7
  end
8
8
 
9
9
  def execute(command)
10
- @bus.(command)
10
+ @bus.call(command)
11
11
  end
12
12
 
13
- def register_command klass, handler
13
+ def register_command(klass, handler)
14
+ Rails.logger.debug("Registered #{klass} to #{handler}")
14
15
  @bus.register(klass, handler)
15
16
  end
16
17
 
17
18
  private
18
- def register_commands
19
- # TODO, Register Commands/Queries
20
- end
19
+
20
+ def register_commands
21
+ # TODO, Register Commands/Queries
22
+ end
21
23
  end
22
- end
24
+ end
@@ -12,7 +12,7 @@ module NexusCqrs
12
12
 
13
13
  # Provide access to the CQRS executor
14
14
  def command_executor
15
- @command_executor ||= NexusCqrs::CommandExecutor.new
15
+ @command_executor ||= $COMMAND_EXECUTOR
16
16
  end
17
17
  end
18
- end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module NexusCqrs
2
- VERSION = "0.0.4"
2
+ VERSION = '0.0.9'
3
3
  end
@@ -1,23 +1,20 @@
1
1
  require_relative 'lib/nexus_cqrs/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "nexus_cqrs"
4
+ spec.name = 'nexus_cqrs'
5
5
  spec.version = NexusCqrs::VERSION
6
- spec.authors = ["Dean Lovett"]
7
- spec.email = ["dean.lovett@nexusmods.com"]
6
+ spec.authors = ['Dean Lovett']
7
+ spec.email = ['dean.lovett@nexusmods.com']
8
8
 
9
- spec.summary = %q{Core package for the nexus cqrs gem}
10
- spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
9
+ spec.summary = 'Core package for the nexus cqrs gem'
10
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
11
11
 
12
12
  # Specify which files should be added to the gem when it is released.
13
13
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
14
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
15
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
14
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
15
+ %x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
16
  end
17
- spec.bindir = "exe"
17
+ spec.bindir = 'exe'
18
18
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
- spec.require_paths = ["lib"]
20
-
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rails", "~> 5"
19
+ spec.require_paths = ['lib']
23
20
  end
metadata CHANGED
@@ -1,43 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_cqrs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dean Lovett
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-08-21 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: bundler
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.3'
20
- type: :development
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::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'
11
+ date: 2020-08-25 00:00:00.000000000 Z
12
+ dependencies: []
41
13
  description:
42
14
  email:
43
15
  - dean.lovett@nexusmods.com
@@ -46,8 +18,11 @@ extensions: []
46
18
  extra_rdoc_files: []
47
19
  files:
48
20
  - ".gitignore"
21
+ - ".gitlab-ci.yml"
22
+ - ".rubocop.yml"
49
23
  - CODE_OF_CONDUCT.md
50
24
  - Gemfile
25
+ - Gemfile.lock
51
26
  - README.md
52
27
  - Rakefile
53
28
  - bin/console