Skip to content

Commit

Permalink
Ruby 3 support - Merge pull request #97 from payrollhero/ruby-3-support
Browse files Browse the repository at this point in the history
Ruby 3 support
  • Loading branch information
mathieujobin authored Sep 20, 2022
2 parents 9eed563 + 41e7ea8 commit 8b36da2
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 35 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ jobs:
fail-fast: false
matrix:
ruby:
- 3.1
- '3.0'
- 2.7
- 2.6
awssdk:
- v1
- v3
Expand All @@ -27,10 +28,10 @@ jobs:
- Gemfile-6-1
- Gemfile-7-0
exclude:
- gemfile: Gemfile-7-0
ruby: 2.6
- gemfile: Gemfile-5-2
ruby: 3.0
ruby: 3.1
- gemfile: Gemfile-5-2
ruby: '3.0'

env:
AWS_SDK_VER: ${{ matrix.awssdk }}
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## [v2.1.0](https://github.com/payrollhero/dispatch-rider/tree/v2.1.0) (2022-09-20)
[Full Changelog](https://github.com/payrollhero/dispatch-rider/compare/v2.0.0...v2.1.0)

* Added support for ruby 3.0 and 3.1
* Require ruby 2.7 at the very minimum, there is a meta-programming class with kwards between 2.6 and 3.0
since 2.6 is not unsupported, support is removed

## [v2.0.0](https://github.com/payrollhero/dispatch-rider/tree/v2.0.0) (2022-09-20)
[Full Changelog](https://github.com/payrollhero/dispatch-rider/compare/v1.9.0...v2.0.0)

Expand Down
2 changes: 1 addition & 1 deletion dispatch-rider.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Gem::Specification.new do |gem|
gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
gem.require_paths = ['lib']
gem.required_ruby_version = '>= 2.6.5'
gem.required_ruby_version = '>= 2.7.2'


gem.add_runtime_dependency 'activesupport', '>= 5.2.0'
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatch-rider/logging/lifecycle_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def translator
end

def translated_message
translator.translate(message, kind, options)
translator.translate(message, kind, **options)
end

def interjected_message
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatch-rider/logging/translator/base_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module DispatchRider
module Logging
class Translator
class BaseTranslator
def initialize(message, **)
def initialize(message)
@message = message
end

Expand Down
14 changes: 4 additions & 10 deletions lib/dispatch-rider/publisher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,17 @@ def register_channel(service, name, options = {})
self
end

# @param [Hash] original_options should contain `:destinations` and `:message` keys
def publish(original_options = {})
options = build_publish_options(original_options)

callbacks.invoke(:publish, options) do
def publish(message:, destinations:)
options = { message: build_message(message), destinations: destinations }
callbacks.invoke(:publish, **options) do
service_channel_mapper.map(options.delete(:destinations)).each do |(service, channels)|
notification_service_registrar.fetch(service).publish(options.merge to: channels)
notification_service_registrar.fetch(service).publish(**(options.merge to: channels))
end
end
end

private

def build_publish_options(message:, destinations:)
{ message: build_message(message), destinations: destinations }
end

def build_message(attributes)
DispatchRider::Message.new(attributes).tap do |message|
message.body[:guid] ||= generate_new_message_id
Expand Down
2 changes: 1 addition & 1 deletion lib/dispatch-rider/publisher/configuration_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def load_config(configuration, publisher)

def configure_notification_services(notification_services, publisher)
notification_services.each do |service|
publisher.register_notification_service(service.name, service.options)
publisher.register_notification_service(service.name, **service.options)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dispatch-rider/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This file specifies the current version of the gem.
module DispatchRider
VERSION = '2.0.0'
VERSION = '2.1.0'
end
15 changes: 12 additions & 3 deletions spec/lib/dispatch-rider/publisher/configuration_reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@
end

it "calls register_notification_service with :file_system and {}" do
expect(publisher).to receive(:register_notification_service).with("file_system", {})
if RUBY_VERSION > '3'
expect(publisher).to receive(:register_notification_service).with("file_system").once
else
expect(publisher).to receive(:register_notification_service).with("file_system", {}).once
end
subject.load_config(configuration, publisher)
end
end
Expand All @@ -71,8 +75,13 @@
end

it "calls register_notification_service with :file_system and {}, as well as :foo, {bar: '123'}" do
expect(publisher).to receive(:register_notification_service).with("file_system", {})
expect(publisher).to receive(:register_notification_service).with("foo", "bar" => "123")
if RUBY_VERSION > '3'
expect(publisher).to receive(:register_notification_service).with("file_system").once
expect(publisher).to receive(:register_notification_service).with("foo", bar: "123").once
else
expect(publisher).to receive(:register_notification_service).with("file_system", {}).once
expect(publisher).to receive(:register_notification_service).with("foo", "bar" => "123").once
end
subject.load_config(configuration, publisher)
end
end
Expand Down
17 changes: 4 additions & 13 deletions spec/lib/dispatch-rider/publisher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,16 @@
describe "calls publish callback" do
describe "calls the publish callback" do
let(:publish_callback) { double :callback }
let(:expected_message) {
DispatchRider::Message.new(
subject: "bar_handler",
body: {
"bar" => "baz",
guid: "test-mode-not-random-guid"
}
)
}

before { DispatchRider.config.callbacks.for(:publish) << publish_callback }

after { DispatchRider.config.callbacks.for(:publish).delete publish_callback }

example do
expect(publish_callback).to receive(:call).with any_args, # first argument is the inner job
destinations: [:fs_foo],
message: expected_message

expect(publish_callback).to receive(:call).with(
an_instance_of(Proc), # first argument is the inner job
{ destinations: [:fs_foo],
message: an_instance_of(DispatchRider::Message) })
publisher.publish destinations: [:fs_foo],
message: {
subject: "bar_handler",
Expand Down
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'bundler/setup'

require 'simplecov'
SimpleCov.minimum_coverage 85
require 'coveralls'

if RUBY_VERSION < "3.1"
Expand Down

0 comments on commit 8b36da2

Please sign in to comment.