diff --git a/Changes.md b/Changes.md index ae7a3f1..219fe04 100644 --- a/Changes.md +++ b/Changes.md @@ -1,3 +1,8 @@ +HEAD +---- + +- Support for Ruby 2.7+ [#93](https://github.com/thbar/kiba/pull/93). Special thanks to @eregon and @mame for their input. + 3.0.0 ----- diff --git a/README.md b/README.md index c996e15..fc1a18c 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ You can also check out the [author blog](https://thibautbarrere.com) and [StackO ## Supported Ruby versions -Kiba currently supports Ruby 2.4-2.6 ([2.7 support is in preliminary tests](https://github.com/thbar/kiba/wiki/Ruby-2.7--keyword-arguments-compatibility-note)) JRuby 9.2+ and TruffleRuby. See [test matrix](https://travis-ci.org/thbar/kiba). +Kiba currently supports Ruby 2.4+, JRuby 9.2+ and TruffleRuby. See [test matrix](https://travis-ci.org/thbar/kiba). ## ETL consulting & commercial version diff --git a/lib/kiba/context.rb b/lib/kiba/context.rb index 2511739..0066155 100644 --- a/lib/kiba/context.rb +++ b/lib/kiba/context.rb @@ -23,5 +23,9 @@ def destination(klass, *initialization_params) def post_process(&block) @control.post_processes << { block: block } end + + [:source, :transform, :destination].each do |m| + ruby2_keywords(m) if respond_to?(:ruby2_keywords, true) + end end end diff --git a/test/shared_runner_tests.rb b/test/shared_runner_tests.rb index 7819a49..a2b81a2 100644 --- a/test/shared_runner_tests.rb +++ b/test/shared_runner_tests.rb @@ -155,4 +155,74 @@ def test_nil_transform_error_message end assert_raises(RuntimeError, 'Nil parameters not allowed here') { kiba_run(control) } end + + def test_ruby_3_source_kwargs + # NOTE: before Ruby 3 kwargs support, a Ruby warning would + # be captured here with Ruby 2.7 & ensure we fail, + # and an error would be raised with Ruby 2.8.0-dev + # NOTE: only the first warning will be captured, though, but + # having 3 different tests is still better + storage = nil + assert_silent do + Kiba.run(Kiba.parse do + source TestKeywordArgumentsComponent, + mandatory: "first", + on_init: -> (values) { storage = values } + end) + end + assert_equal({ + mandatory: "first", + optional: nil + }, storage) + end + + def test_ruby_3_transform_kwargs + storage = nil + assert_silent do + Kiba.run(Kiba.parse do + transform TestKeywordArgumentsComponent, + mandatory: "first", + on_init: -> (values) { storage = values } + end) + end + assert_equal({ + mandatory: "first", + optional: nil + }, storage) + end + + def test_ruby_3_destination_kwargs + storage = nil + assert_silent do + Kiba.run(Kiba.parse do + destination TestKeywordArgumentsComponent, + mandatory: "first", + on_init: -> (values) { storage = values } + end) + end + assert_equal({ + mandatory: "first", + optional: nil + }, storage) + end + + def test_positional_plus_keyword_arguments + storage = nil + assert_silent do + Kiba.run(Kiba.parse do + source TestMixedArgumentsComponent, + "some positional argument", + mandatory: "first", + on_init: -> (values) { + storage = values + } + end) + end + + assert_equal({ + some_value: "some positional argument", + mandatory: "first", + optional: nil + }, storage) + end end diff --git a/test/support/test_keyword_arguments_component.rb b/test/support/test_keyword_arguments_component.rb new file mode 100644 index 0000000..3aea224 --- /dev/null +++ b/test/support/test_keyword_arguments_component.rb @@ -0,0 +1,14 @@ +# a mock component to test Ruby 3 keyword argument support +class TestKeywordArgumentsComponent + def initialize(mandatory:, optional: nil, on_init: nil) + values = { + mandatory: mandatory, + optional: optional + } + on_init&.call(values) + end + + def each + # no-op + end +end diff --git a/test/support/test_mixed_arguments_component.rb b/test/support/test_mixed_arguments_component.rb new file mode 100644 index 0000000..eebc08d --- /dev/null +++ b/test/support/test_mixed_arguments_component.rb @@ -0,0 +1,14 @@ +# a mock component to test Ruby 3 keyword argument support +class TestMixedArgumentsComponent + def initialize(some_value, mandatory:, optional: nil, on_init:) + @values = {} + @values[:some_value] = some_value + @values[:mandatory] = mandatory + @values[:optional] = optional + on_init&.call(@values) + end + + def each + # no-op + end +end diff --git a/test/test_streaming_runner.rb b/test/test_streaming_runner.rb index a1c6055..648e1d4 100644 --- a/test/test_streaming_runner.rb +++ b/test/test_streaming_runner.rb @@ -6,6 +6,8 @@ require_relative 'support/test_close_yielding_transform' require_relative 'support/test_non_closing_transform' require_relative 'shared_runner_tests' +require_relative 'support/test_keyword_arguments_component' +require_relative 'support/test_mixed_arguments_component' class TestStreamingRunner < Kiba::Test def kiba_run(job)