Skip to content

Commit

Permalink
add rubocop as development dependency (#4)
Browse files Browse the repository at this point in the history
* add rubocop and fix offenses
  • Loading branch information
ahmad-elassuty authored Aug 20, 2020
1 parent 84f7471 commit 156364e
Show file tree
Hide file tree
Showing 26 changed files with 164 additions and 123 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Quality
on: push

jobs:
rubocop:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- uses: ruby/setup-ruby@v1
with:
bundler-cache: true

- run: bundle
- run: bundle exec rubocop
16 changes: 16 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
AllCops:
NewCops: enable

Style/FrozenStringLiteralComment:
Exclude:
- spec/**/*
- bin/**/*

Metrics/BlockLength:
Exclude:
- spec/**/*

# [TODO] Turn on documentation rule
Style/Documentation:
Enabled: false

1 change: 1 addition & 0 deletions .ruby-gemset
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
event_router
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.7.1
6 changes: 0 additions & 6 deletions .travis.yml

This file was deleted.

7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
source "https://rubygems.org"
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in event_router.gemspec
gemspec

gem "rake", "~> 12.0"
gem "rspec", "~> 3.0"
24 changes: 22 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ GEM
minitest (~> 5.1)
tzinfo (~> 1.1)
zeitwerk (~> 2.2, >= 2.2.2)
ast (2.4.1)
byebug (11.1.3)
coderay (1.1.3)
concurrent-ruby (1.1.7)
Expand All @@ -27,15 +28,20 @@ GEM
concurrent-ruby (~> 1.0)
method_source (1.0.0)
minitest (5.14.1)
parallel (1.19.2)
parser (2.7.1.4)
ast (~> 2.4.1)
pry (0.13.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.9.0)
byebug (~> 11.0)
pry (~> 0.13.0)
rack (2.2.3)
rake (12.3.3)
rainbow (3.0.0)
redis (4.2.1)
regexp_parser (1.7.1)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
Expand All @@ -49,23 +55,37 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.1)
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)
sidekiq (6.1.1)
connection_pool (>= 2.2.2)
rack (~> 2.0)
redis (>= 4.2.0)
thread_safe (0.3.6)
tzinfo (1.2.7)
thread_safe (~> 0.1)
unicode-display_width (1.7.0)
zeitwerk (2.4.0)

PLATFORMS
ruby

DEPENDENCIES
event_router!
pry
pry-byebug
rake (~> 12.0)
rspec (~> 3.0)
rubocop
sidekiq

BUNDLED WITH
Expand Down
8 changes: 5 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require "bundler/gem_tasks"
require "rspec/core/rake_task"
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
8 changes: 4 additions & 4 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "event_router"
require 'bundler/setup'
require 'event_router'

# 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.
Expand All @@ -10,5 +10,5 @@ require "event_router"
# require "pry"
# Pry.start

require "irb"
IRB.start(__FILE__)
require 'pry'
Pry.start(__FILE__)
37 changes: 21 additions & 16 deletions event_router.gemspec
Original file line number Diff line number Diff line change
@@ -1,34 +1,39 @@
# frozen_string_literal: true

require_relative 'lib/event_router/version'

Gem::Specification.new do |spec|
spec.name = "event_router"
spec.name = 'event_router'
spec.version = EventRouter::VERSION
spec.authors = ["Ahmad Elassuty"]
spec.email = ["[email protected]"]
spec.authors = ['Ahmad Elassuty']
spec.email = ['[email protected]']

spec.summary = "A simple event router gem"
spec.homepage = "https://github.com/ahmad-elassuty/event_router"
spec.license = "MIT"
spec.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
spec.summary = 'A simple event router gem'
spec.homepage = 'https://github.com/ahmad-elassuty/event_router'
spec.license = 'MIT'
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')

spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = spec.homepage

# 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
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`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']

# Dependencies
spec.add_dependency "activejob"
spec.add_dependency 'activejob'

# Development dependencies
spec.add_development_dependency "sidekiq"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency 'pry'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_development_dependency 'sidekiq'
end
45 changes: 16 additions & 29 deletions lib/event_router.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
require "event_router/version"
require "event_router/error"
require "active_job"
require "event_router/configuration"
require "event_router/destination"
require "event_router/event"
require "event_router/event_serializer"
require "event_router/deliver_event_job"

require "examples/notifications"
require "examples/event_store/order_placed"
require "examples/order_placed"
require "examples/payment_received"

require "pry"
# frozen_string_literal: true

module EventRouter
module_function

def schedule_single_event
ActiveJob::Serializers.add_serializers EventSerializer

Examples::OrderPlaced.publish(order_id: 1)
end
require 'event_router/version'
require 'event_router/error'
require 'active_job'
require 'event_router/configuration'
require 'event_router/destination'
require 'event_router/event'
require 'event_router/event_serializer'
require 'event_router/deliver_event_job'

def schedule_multiple_events
ActiveJob::Serializers.add_serializers EventSerializer
require 'examples/notifications'
require 'examples/event_store/order_placed'
require 'examples/order_placed'
require 'examples/payment_received'

event_1 = Examples::OrderPlaced.new(order_id: 1)
event_2 = Examples::PaymentReceived.new(order_id: 2)
require 'pry'

publish(event_1, event_2)
end
module EventRouter
module_function

def publish(*events)
correlation_id = events.first.correlation_id
Expand Down
20 changes: 10 additions & 10 deletions lib/event_router/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative "errors/unsupported_option_error"
require_relative 'errors/unsupported_option_error'

module EventRouter
class Configuration
Expand All @@ -27,25 +27,25 @@ def initialize
end

def delivery_adapter=(adapter)
validate_inclusion!(:delivery_adapter, adapter, DELIVERY_ADAPTERS)
validate_inclusion(:delivery_adapter, adapter, DELIVERY_ADAPTERS)

@delivery_adapter = adapter
end

def delivery_strategy=(strategy)
validate_inclusion!(:delivery_strategy, strategy, DELIVERY_STRATEGIES)
validate_inclusion(:delivery_strategy, strategy, DELIVERY_STRATEGIES)

@delivery_strategy = strategy
end

private
private

def validate_inclusion!(config, option, supported_options)
unless supported_options.include?(option)
raise Errors::UnsupportedOptionError.new(
config: config, option: option, supported_options: supported_options
)
end
def validate_inclusion(config, option, supported_options)
return if supported_options.include?(option)

raise Errors::UnsupportedOptionError.new(
config: config, option: option, supported_options: supported_options
)
end
end
end
10 changes: 7 additions & 3 deletions lib/event_router/deliver_event_job.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# frozen_string_literal: true

require "pry"
require 'pry'

module EventRouter
class DeliverEventJob < ActiveJob::Base
self.queue_adapter = :sidekiq

def perform(destination, event, payload)
binding.pry
event.destinations[destination]&.process(event, payload)
destination = event.destinations[destination]

return if destination.blank?

payload ||= destination.payload_for(event)
destination.process(event, payload)
end
end
end
4 changes: 2 additions & 2 deletions lib/event_router/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module EventRouter
class Destination
# Attributes
attr_reader :name, :handler, :handler_method,
:prefetch_payload, :payload_method
:prefetch_payload, :payload_method

# Constants
DEFAULT_ATTRIBUTES = {
Expand All @@ -31,7 +31,7 @@ def process(event, payload)
handler.send(
handler_method || event.name,
event: event,
payload: payload || payload_for(event)
payload: payload
)
end

Expand Down
1 change: 0 additions & 1 deletion lib/event_router/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
module EventRouter
class Error < StandardError; end
end

5 changes: 2 additions & 3 deletions lib/event_router/errors/unsupported_option_error.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require_relative "../error"
require_relative '../error'

module EventRouter
module Errors
Expand All @@ -14,8 +14,7 @@ def initialize(message: nil, config:, option:, supported_options:)
end

def message
"Unsupported #{@option} for #{@config} configuration." +
" Currently supports #{@supported_options}"
"Unsupported #{@option} for #{@config} configuration. Currently supports #{@supported_options}"
end
end
end
Expand Down
3 changes: 1 addition & 2 deletions lib/event_router/event.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

require "securerandom"
require 'securerandom'

module EventRouter
class Event
Expand Down Expand Up @@ -46,5 +46,4 @@ def publish(**attrs)
end
end
end

end
Loading

0 comments on commit 156364e

Please sign in to comment.