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

chore: rubocop and CI

parent cd1b438f
No related branches found
No related tags found
Loading
Pipeline #8152 failed
Showing
with 88 additions and 46 deletions
image: "ruby:2.7"
before_script:
- sudo apt-get update -qq && sudo apt-get install -y -qq sqlite3 libsqlite3-dev nodejs
- ruby -v
- which ruby
- gem install bundler --no-document
- bundle install --jobs $(nproc) "${FLAGS[@]}"
rspec:
script:
- bundle exec rspec
rubocop:
script:
- bundle exec rubocop
\ No newline at end of file
inherit_gem:
rubocop-shopify: rubocop.yml
AllCops:
Exclude:
- 'lib/generators/nexus_cqrs/templates/**/*.rb'
Style/GlobalVars:
Enabled: false
\ No newline at end of file
source "https://rubygems.org"
source 'https://rubygems.org'
# Specify your gem's dependencies in cqrs-core.gemspec
gemspec
gem "rubocop"
gem 'rubocop'
gem 'rubocop-shopify', "~> 1.0.4", require: false
......@@ -13,17 +13,19 @@ GEM
rainbow (3.0.0)
regexp_parser (1.7.1)
rexml (3.2.4)
rubocop (0.89.1)
rubocop (0.86.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.7)
rexml
rubocop-ast (>= 0.3.0, < 1.0)
rubocop-ast (>= 0.0.3, < 1.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 2.0)
rubocop-ast (0.3.0)
parser (>= 2.7.1.4)
rubocop-shopify (1.0.4)
rubocop (>= 0.85, < 0.87)
ruby-progressbar (1.10.1)
unicode-display_width (1.7.0)
......@@ -33,6 +35,7 @@ PLATFORMS
DEPENDENCIES
nexus_cqrs!
rubocop
rubocop-shopify (~> 1.0.4)
BUNDLED WITH
2.1.4
require "bundler/gem_tasks"
task :default => :spec
require 'bundler/gem_tasks'
task(default: :spec)
#!/usr/bin/env ruby
require "bundler/setup"
require "cqrs/core"
require 'bundler/setup'
require 'cqrs/core'
# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.
......@@ -10,5 +10,5 @@ require "cqrs/core"
# require "pry"
# Pry.start
require "irb"
require 'irb'
IRB.start(__FILE__)
......@@ -5,18 +5,25 @@ module NexusCqrs
source_root File.expand_path('templates', __dir__)
def copy_command_file
template "command.rb", "app/domain/commands/#{file_name}.rb"
template "command_handler.rb", "app/domain/commands/#{file_name}_handler.rb"
# TODO: add namespace support
full_name = file_name
template('command.rb', "app/domain/commands/#{full_name}.rb")
template('command_handler.rb', "app/domain/commands/#{full_name}_handler.rb")
register_command(full_name)
end
def register_command
handler_config = "config/initializers/register_cqrs_handlers.rb"
def register_command(full_name)
handler_config = 'config/initializers/register_cqrs_handlers.rb'
unless File.exist?('config/initializers/register_cqrs_handlers.rb')
template "register_cqrs_handlers.rb", handler_config
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"
code_to_inject = "$QUERY_EXECUTOR.register_command(#{full_name}, #{full_name}Handler)"
inject_into_file(handler_config, code_to_inject, after: '# Register Commands')
end
end
end
......@@ -5,8 +5,8 @@ module NexusCqrs
source_root File.expand_path('templates', __dir__)
def copy_query_file
template "query.rb", "app/domain/queries/#{file_name}.rb"
template "query_handler.rb", "app/domain/queries/#{file_name}_handler.rb"
template('query.rb', "app/domain/queries/#{file_name}.rb")
template('query_handler.rb', "app/domain/queries/#{file_name}_handler.rb")
end
end
end
......@@ -6,4 +6,4 @@ $QUERY_EXECUTOR = NexusCqrs::CommandExecutor.new query_bus
# Register Queries
# Register Commands
\ No newline at end of file
# Register Commands
......@@ -8,4 +8,4 @@ require 'nexus_cqrs/helpers'
module NexusCqrs
class Error < StandardError; end
end
\ No newline at end of file
end
module NexusCqrs
class BaseCommand
end
end
\ No newline at end of file
end
module NexusCqrs
class BaseCommandHandler
end
end
\ No newline at end of file
end
module NexusCqrs
class BaseQuery
end
end
\ No newline at end of file
end
module NexusCqrs
class BaseQueryHandler
end
end
\ No newline at end of file
end
......@@ -7,21 +7,25 @@ module NexusCqrs
def initialize
@handlers =
ThreadSafe::Cache.new
ThreadSafe::Cache.new
end
def register(klass, handler)
raise MultipleHandlers.new("Multiple handlers not allowed for #{klass}") if handlers[klass]
raise MultipleHandlers, "Multiple handlers not allowed for #{klass}" if handlers[klass]
handlers[klass] = handler
end
def call(command)
unregistered_handler = proc { raise UnregisteredHandler, "Missing handler for #{command.class}" }
handlers
.fetch(command.class) { raise UnregisteredHandler.new("Missing handler for #{command.class}") }
.(command)
.fetch(command.class, &unregistered_handler)
.call(command)
end
private
attr_reader :handlers
end
end
\ No newline at end of file
end
......@@ -7,17 +7,18 @@ module NexusCqrs
end
def execute(command)
@bus.(command)
@bus.call(command)
end
def register_command klass, handler
Rails.logger.debug "Registered #{klass} to #{handler}"
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
end
def register_commands
# TODO, Register Commands/Queries
end
end
end
\ No newline at end of file
end
......@@ -15,4 +15,4 @@ module NexusCqrs
@command_executor ||= $COMMAND_EXECUTOR
end
end
end
\ No newline at end of file
end
module NexusCqrs
VERSION = "0.0.6"
VERSION = '0.0.6'
end
require_relative 'lib/nexus_cqrs/version'
Gem::Specification.new do |spec|
spec.name = "nexus_cqrs"
spec.name = 'nexus_cqrs'
spec.version = NexusCqrs::VERSION
spec.authors = ["Dean Lovett"]
spec.email = ["dean.lovett@nexusmods.com"]
spec.authors = ['Dean Lovett']
spec.email = ['dean.lovett@nexusmods.com']
spec.summary = %q{Core package for the nexus cqrs gem}
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
spec.summary = 'Core package for the nexus cqrs gem'
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
spec.files = Dir.chdir(File.expand_path(__dir__)) do
%x(git ls-files -z).split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
spec.require_paths = ['lib']
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