nexus_cqrs 0.0.1 → 0.0.6

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: c62728d657d12e0238fa6d56e85de427f66d9f3521941b320aa087193e53eaa4
4
- data.tar.gz: 432a2ebc8bdf0fda72f954704738620d30c0a2c756e174b5982e90576c7b5cb2
3
+ metadata.gz: 166e19872cf44b2a581e7d3c3c744c1500bf9b6259dff4678e1b6a817d2b8b64
4
+ data.tar.gz: ebe24c347b567a40f529e0b8409fff8d1bb9410044b03d7b03e6cae896d6e8d4
5
5
  SHA512:
6
- metadata.gz: b2d3f76090eab365459d245f34fda9229dfdb4ecc2e749ef0e38eb7c27e12b2ee3a72b88b52aa7ffe63ca3f0b10bc4ee9f7ff3a4acbc966f8d6b0ddd180c55c0
7
- data.tar.gz: c96f30c32b942efebd1eeded9a4816c4fcb2616f82a7a47c16ff392448967f0f709d447b08e2192faa689a6383e1e9037b881f1e26f222c475bfe2e7e3f7a8d4
6
+ metadata.gz: 519f57716334745b55e303914758549f0b2652d94c353d3bd78264f73db44f5e47a4eaa9aeb3e6bef017f49c44e0fea7745c2a671fad72972d830da52e59e0f7
7
+ data.tar.gz: 3dd5eba476cc5b87d3c0217417ab5e8323fce73f925db26fccfd79b9e02a18ff6daff5e55adec12cd9b45cb0b45849f1ba4fc01dc5cf8c82b0c86b8e6f4daa5b
data/.gitignore CHANGED
@@ -6,3 +6,6 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /.gem
10
+
11
+ *.gem
data/README.md CHANGED
@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'cqrs-core'
12
+ gem 'nexus_cqrs'
13
13
  ```
14
14
 
15
15
  And then execute:
@@ -18,23 +18,14 @@ And then execute:
18
18
 
19
19
  Or install it yourself as:
20
20
 
21
- $ gem install cqrs-core
21
+ $ gem install nexus_cqrs
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ Generators can be used to aide in the creation of Commands and Queries:
26
26
 
27
- ## Development
27
+ rails g nexus_cqrs:command CommandName
28
+ rails g nexus_cqrs:query QueryName
28
29
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+ Once installed, a CommandBus is required to control the flow of Commands and/or Queries:
30
31
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cqrs-core. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/cqrs-core/blob/master/CODE_OF_CONDUCT.md).
36
-
37
-
38
- ## Code of Conduct
39
-
40
- Everyone interacting in the Cqrs::Core project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/cqrs-core/blob/master/CODE_OF_CONDUCT.md).
@@ -8,5 +8,15 @@ module NexusCqrs
8
8
  template "command.rb", "app/domain/commands/#{file_name}.rb"
9
9
  template "command_handler.rb", "app/domain/commands/#{file_name}_handler.rb"
10
10
  end
11
+
12
+ def register_command
13
+ handler_config = "config/initializers/register_cqrs_handlers.rb"
14
+
15
+ unless File.exist?('config/initializers/register_cqrs_handlers.rb')
16
+ template "register_cqrs_handlers.rb", handler_config
17
+ end
18
+
19
+ inject_into_file handler_config, "$QUERY_EXECUTOR.register_command(Queries::Stripe::GetCustomerById, Queries::Stripe::GetCustomerByIdHandler)", after: "# Register Commands"
20
+ end
11
21
  end
12
22
  end
@@ -1,5 +1,5 @@
1
1
  module Commands
2
- class <%= class_name %> < BaseCommand
2
+ class <%= class_name %> < NexusCqrs::BaseCommand
3
3
 
4
4
  # Define attributes for this command
5
5
  attr_accessor :id
@@ -1,5 +1,5 @@
1
1
  module Commands
2
- class <%= class_name %>Handler < BaseCommandHandler
2
+ class <%= class_name %>Handler < NexusCqrs::BaseCommandHandler
3
3
 
4
4
  # call is where the Command is executed
5
5
  def call(command)
@@ -1,5 +1,5 @@
1
1
  module Queries
2
- class <%= class_name %> < BaseQuery
2
+ class <%= class_name %> < NexusCqrs::BaseQuery
3
3
 
4
4
  # Define attributes for this query
5
5
  attr_accessor :id
@@ -1,5 +1,5 @@
1
1
  module Queries
2
- class <%= class_name %>Handler < BaseQueryHandler
2
+ class <%= class_name %>Handler < NexusCqrs::BaseQueryHandler
3
3
 
4
4
  # call is where the Query is executed
5
5
  def call(command)
@@ -0,0 +1,9 @@
1
+ command_bus = NexusCqrs::CommandBus.new
2
+ query_bus = NexusCqrs::CommandBus.new
3
+
4
+ $COMMAND_EXECUTOR = NexusCqrs::CommandExecutor.new command_bus
5
+ $QUERY_EXECUTOR = NexusCqrs::CommandExecutor.new query_bus
6
+
7
+ # Register Queries
8
+
9
+ # Register Commands
@@ -0,0 +1,11 @@
1
+ require 'nexus_cqrs/base_command'
2
+ require 'nexus_cqrs/base_command_handler'
3
+ require 'nexus_cqrs/base_query'
4
+ require 'nexus_cqrs/base_query_handler'
5
+ require 'nexus_cqrs/command_bus'
6
+ require 'nexus_cqrs/command_executor'
7
+ require 'nexus_cqrs/helpers'
8
+
9
+ module NexusCqrs
10
+ class Error < StandardError; end
11
+ end
@@ -18,7 +18,7 @@ module NexusCqrs
18
18
  def call(command)
19
19
  handlers
20
20
  .fetch(command.class) { raise UnregisteredHandler.new("Missing handler for #{command.class}") }
21
- .(command)
21
+ .run(command)
22
22
  end
23
23
 
24
24
  private
@@ -1,7 +1,7 @@
1
1
  module NexusCqrs
2
2
  class CommandExecutor
3
- def initialize
4
- @bus = CommandBus.new
3
+ def initialize(command_bus)
4
+ @bus = command_bus
5
5
 
6
6
  register_commands
7
7
  end
@@ -10,6 +10,11 @@ module NexusCqrs
10
10
  @bus.(command)
11
11
  end
12
12
 
13
+ def register_command klass, handler
14
+ Rails.logger.debug "Registered #{klass} to #{handler}"
15
+ @bus.register(klass, handler)
16
+ end
17
+
13
18
  private
14
19
  def register_commands
15
20
  # TODO, Register Commands/Queries
@@ -2,17 +2,12 @@ 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
- command_executor.execute(query)
11
- end
12
-
13
- # Provide access to the CQRS executor
14
- def command_executor
15
- @command_executor ||= NexusCqrs::CommandExecutor.new
10
+ $QUERY_EXECUTOR.execute(query)
16
11
  end
17
12
  end
18
13
  end
@@ -1,3 +1,3 @@
1
1
  module NexusCqrs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.6"
3
3
  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.0.1
4
+ version: 0.0.6
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-20 00:00:00.000000000 Z
11
+ date: 2020-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -59,6 +59,8 @@ files:
59
59
  - lib/generators/nexus_cqrs/templates/command_handler.rb
60
60
  - lib/generators/nexus_cqrs/templates/query.rb
61
61
  - lib/generators/nexus_cqrs/templates/query_handler.rb
62
+ - lib/generators/nexus_cqrs/templates/register_cqrs_handlers.rb
63
+ - lib/nexus_cqrs.rb
62
64
  - lib/nexus_cqrs/base_command.rb
63
65
  - lib/nexus_cqrs/base_command_handler.rb
64
66
  - lib/nexus_cqrs/base_query.rb