nexus_cqrs 0.0.6 → 0.0.7

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: 166e19872cf44b2a581e7d3c3c744c1500bf9b6259dff4678e1b6a817d2b8b64
4
- data.tar.gz: ebe24c347b567a40f529e0b8409fff8d1bb9410044b03d7b03e6cae896d6e8d4
3
+ metadata.gz: 23309f2a97f391f3a2862722c27c512f008253c52e42340286d1d5717d854520
4
+ data.tar.gz: f5af26755f89d08af6adc420e92488e634916992dc5723dbd1f1a83bed0b990c
5
5
  SHA512:
6
- metadata.gz: 519f57716334745b55e303914758549f0b2652d94c353d3bd78264f73db44f5e47a4eaa9aeb3e6bef017f49c44e0fea7745c2a671fad72972d830da52e59e0f7
7
- data.tar.gz: 3dd5eba476cc5b87d3c0217417ab5e8323fce73f925db26fccfd79b9e02a18ff6daff5e55adec12cd9b45cb0b45849f1ba4fc01dc5cf8c82b0c86b8e6f4daa5b
6
+ metadata.gz: 428a3c2707b17c1ff953fe50a90b2fc65b50500165bc502c7c8112dd78074093e95b75bcab6efb89da8c66fd7e7012cc78dfa206a114dcfae1ac8c088e3ea862
7
+ data.tar.gz: e5fe947c629472f7ac1078ea941ffebdcb8f03c4fdc8877f759c9507f0cb90e9f93c42df87b90d892a9c403b3e429efc1f826df23ca773003bda11ae69d5a8e7
@@ -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
1
  source "https://rubygems.org"
2
+ source 'https://rubygems.org'
2
3
 
3
4
  # Specify your gem's dependencies in cqrs-core.gemspec
4
5
  gemspec
5
6
 
6
- gem "rake", "~> 12.0"
7
+ gem 'rubocop'
8
+ gem 'rubocop-shopify', "~> 1.0.4", require: false
9
+
10
+ gem 'rspec'
11
+ gem 'thread_safe'
@@ -0,0 +1,58 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nexus_cqrs (0.0.6)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ diff-lcs (1.4.4)
11
+ parallel (1.19.2)
12
+ parser (2.7.1.4)
13
+ ast (~> 2.4.1)
14
+ rainbow (3.0.0)
15
+ regexp_parser (1.7.1)
16
+ rexml (3.2.4)
17
+ rspec (3.9.0)
18
+ rspec-core (~> 3.9.0)
19
+ rspec-expectations (~> 3.9.0)
20
+ rspec-mocks (~> 3.9.0)
21
+ rspec-core (3.9.2)
22
+ rspec-support (~> 3.9.3)
23
+ rspec-expectations (3.9.2)
24
+ diff-lcs (>= 1.2.0, < 2.0)
25
+ rspec-support (~> 3.9.0)
26
+ rspec-mocks (3.9.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-support (3.9.3)
30
+ rubocop (0.86.0)
31
+ parallel (~> 1.10)
32
+ parser (>= 2.7.0.1)
33
+ rainbow (>= 2.2.2, < 4.0)
34
+ regexp_parser (>= 1.7)
35
+ rexml
36
+ rubocop-ast (>= 0.0.3, < 1.0)
37
+ ruby-progressbar (~> 1.7)
38
+ unicode-display_width (>= 1.4.0, < 2.0)
39
+ rubocop-ast (0.3.0)
40
+ parser (>= 2.7.1.4)
41
+ rubocop-shopify (1.0.4)
42
+ rubocop (>= 0.85, < 0.87)
43
+ ruby-progressbar (1.10.1)
44
+ thread_safe (0.3.6)
45
+ unicode-display_width (1.7.0)
46
+
47
+ PLATFORMS
48
+ ruby
49
+
50
+ DEPENDENCIES
51
+ nexus_cqrs!
52
+ rspec
53
+ rubocop
54
+ rubocop-shopify (~> 1.0.4)
55
+ thread_safe
56
+
57
+ BUNDLED WITH
58
+ 2.1.4
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,25 @@ 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
+ # TODO: add namespace support
9
+ full_name = file_name
10
+
11
+ template('command.rb', "app/domain/commands/#{full_name}.rb")
12
+ template('command_handler.rb', "app/domain/commands/#{full_name}_handler.rb")
13
+
14
+ register_command(full_name)
10
15
  end
11
16
 
12
- def register_command
13
- handler_config = "config/initializers/register_cqrs_handlers.rb"
17
+ def register_command(full_name)
18
+ handler_config = 'config/initializers/register_cqrs_handlers.rb'
14
19
 
15
20
  unless File.exist?('config/initializers/register_cqrs_handlers.rb')
16
- template "register_cqrs_handlers.rb", handler_config
21
+ template('register_cqrs_handlers.rb', handler_config)
17
22
  end
18
23
 
19
- inject_into_file handler_config, "$QUERY_EXECUTOR.register_command(Queries::Stripe::GetCustomerById, Queries::Stripe::GetCustomerByIdHandler)", after: "# Register Commands"
24
+ code_to_inject = "$QUERY_EXECUTOR.register_command(#{full_name}, #{full_name}Handler)"
25
+
26
+ inject_into_file(handler_config, code_to_inject, after: '# Register Commands')
20
27
  end
21
28
  end
22
29
  end
@@ -5,8 +5,8 @@ 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
+ template('query.rb', "app/domain/queries/#{file_name}.rb")
9
+ template('query_handler.rb', "app/domain/queries/#{file_name}_handler.rb")
10
10
  end
11
11
  end
12
12
  end
@@ -6,4 +6,4 @@ $QUERY_EXECUTOR = NexusCqrs::CommandExecutor.new query_bus
6
6
 
7
7
  # Register Queries
8
8
 
9
- # Register Commands
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,4 @@
1
1
  module NexusCqrs
2
2
  class BaseQueryHandler
3
3
  end
4
- end
4
+ 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
- .run(command)
22
29
  end
23
30
 
24
31
  private
32
+
25
33
  attr_reader :handlers
26
34
  end
27
- end
35
+ end
@@ -7,17 +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
14
- Rails.logger.debug "Registered #{klass} to #{handler}"
13
+ def register_command(klass, handler)
14
+ Rails.logger.debug("Registered #{klass} to #{handler}")
15
15
  @bus.register(klass, handler)
16
16
  end
17
17
 
18
18
  private
19
- def register_commands
20
- # TODO, Register Commands/Queries
21
- end
19
+
20
+ def register_commands
21
+ # TODO, Register Commands/Queries
22
+ end
22
23
  end
23
- end
24
+ end
@@ -2,12 +2,17 @@ module NexusCqrs
2
2
  module Helpers
3
3
  # Executes a CQRS Command
4
4
  def execute(command)
5
- $COMMAND_EXECUTOR.execute(command)
5
+ command_executor.execute(command)
6
6
  end
7
7
 
8
8
  # Executes a CQRS Query
9
9
  def query(query)
10
- $QUERY_EXECUTOR.execute(query)
10
+ command_executor.execute(query)
11
+ end
12
+
13
+ # Provide access to the CQRS executor
14
+ def command_executor
15
+ @command_executor ||= $COMMAND_EXECUTOR
11
16
  end
12
17
  end
13
- end
18
+ end
@@ -1,3 +1,3 @@
1
1
  module NexusCqrs
2
- VERSION = "0.0.6"
2
+ VERSION = '0.0.7'
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.6
4
+ version: 0.0.7
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-24 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