Skip to content
Snippets Groups Projects
Commit cd1b438f authored by Dean Lovett's avatar Dean Lovett
Browse files

fix: fixed various issues with commands and namespaces

parent 812be5bc
No related branches found
No related tags found
No related merge requests found
......@@ -3,4 +3,4 @@ source "https://rubygems.org"
# Specify your gem's dependencies in cqrs-core.gemspec
gemspec
gem "rake", "~> 12.0"
gem "rubocop"
PATH
remote: .
specs:
nexus_cqrs (0.0.6)
GEM
remote: https://rubygems.org/
specs:
ast (2.4.1)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
rainbow (3.0.0)
regexp_parser (1.7.1)
rexml (3.2.4)
rubocop (0.89.1)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.3.0, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
ruby-progressbar (1.10.1)
unicode-display_width (1.7.0)
PLATFORMS
ruby
DEPENDENCIES
nexus_cqrs!
rubocop
BUNDLED WITH
2.1.4
......@@ -9,7 +9,7 @@ TODO: Delete this and the text above, and describe your gem
Add this line to your application's Gemfile:
```ruby
gem 'cqrs-core'
gem 'nexus_cqrs'
```
And then execute:
......@@ -18,23 +18,14 @@ And then execute:
Or install it yourself as:
$ gem install cqrs-core
$ gem install nexus_cqrs
## Usage
TODO: Write usage instructions here
Generators can be used to aide in the creation of Commands and Queries:
## Development
rails g nexus_cqrs:command CommandName
rails g nexus_cqrs:query QueryName
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.
Once installed, a CommandBus is required to control the flow of Commands and/or Queries:
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).
## Contributing
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).
## Code of Conduct
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
template "command.rb", "app/domain/commands/#{file_name}.rb"
template "command_handler.rb", "app/domain/commands/#{file_name}_handler.rb"
end
def register_command
handler_config = "config/initializers/register_cqrs_handlers.rb"
unless File.exist?('config/initializers/register_cqrs_handlers.rb')
template "register_cqrs_handlers.rb", handler_config
end
inject_into_file handler_config, "$QUERY_EXECUTOR.register_command(Queries::Stripe::GetCustomerById, Queries::Stripe::GetCustomerByIdHandler)", after: "# Register Commands"
end
end
end
module Commands
class <%= class_name %> < BaseCommand
class <%= class_name %> < NexusCqrs::BaseCommand
# Define attributes for this command
attr_accessor :id
......
module Commands
class <%= class_name %>Handler < BaseCommandHandler
class <%= class_name %>Handler < NexusCqrs::BaseCommandHandler
# call is where the Command is executed
def call(command)
......
module Queries
class <%= class_name %> < BaseQuery
class <%= class_name %> < NexusCqrs::BaseQuery
# Define attributes for this query
attr_accessor :id
......
module Queries
class <%= class_name %>Handler < BaseQueryHandler
class <%= class_name %>Handler < NexusCqrs::BaseQueryHandler
# call is where the Query is executed
def call(command)
......
command_bus = NexusCqrs::CommandBus.new
query_bus = NexusCqrs::CommandBus.new
$COMMAND_EXECUTOR = NexusCqrs::CommandExecutor.new command_bus
$QUERY_EXECUTOR = NexusCqrs::CommandExecutor.new query_bus
# Register Queries
# Register Commands
\ No newline at end of file
require 'nexus_cqrs/base_command'
require 'nexus_cqrs/base_command_handler'
require 'nexus_cqrs/base_query'
require 'nexus_cqrs/base_query_handler'
require 'nexus_cqrs/command_bus'
require 'nexus_cqrs/command_executor'
require 'nexus_cqrs/helpers'
module NexusCqrs
class Error < StandardError; end
end
\ No newline at end of file
module NexusCqrs
class CommandExecutor
def initialize
@bus = CommandBus.new
def initialize(command_bus)
@bus = command_bus
register_commands
end
......@@ -10,6 +10,11 @@ module NexusCqrs
@bus.(command)
end
def register_command klass, handler
Rails.logger.debug "Registered #{klass} to #{handler}"
@bus.register(klass, handler)
end
private
def register_commands
# TODO, Register Commands/Queries
......
......@@ -12,7 +12,7 @@ module NexusCqrs
# Provide access to the CQRS executor
def command_executor
@command_executor ||= NexusCqrs::CommandExecutor.new
@command_executor ||= $COMMAND_EXECUTOR
end
end
end
\ No newline at end of file
module NexusCqrs
VERSION = "0.0.2"
VERSION = "0.0.6"
end
......@@ -17,7 +17,4 @@ Gem::Specification.new do |spec|
spec.bindir = "exe"
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rails", "~> 5"
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment