From 3dd5d6026fc7b6918dfbb0b3f2d4cd414e779453 Mon Sep 17 00:00:00 2001 From: vladholovchak Date: Wed, 2 Oct 2024 13:13:14 +0300 Subject: [PATCH] update to ruby 3 --- lib/pipey.rb | 2 -- lib/pipey/chain.rb | 10 +++++----- lib/pipey/core.rb | 8 ++++---- lib/pipey/extensions.rb | 2 +- lib/pipey/line.rb | 10 +++++----- lib/pipey/steps.rb | 4 ++-- pipey.gemspec | 3 +-- test/pipey/chain_test.rb | 3 --- test/pipey/line_test.rb | 4 ++-- 9 files changed, 20 insertions(+), 26 deletions(-) diff --git a/lib/pipey.rb b/lib/pipey.rb index c64b5ab..e2e981f 100644 --- a/lib/pipey.rb +++ b/lib/pipey.rb @@ -2,8 +2,6 @@ require 'pipey/line' require 'pipey/chain' require 'pipey/steps' -require 'pipey/steps' -require 'pipey/extensions' require 'pipey/extensions' module Pipey diff --git a/lib/pipey/chain.rb b/lib/pipey/chain.rb index 8d97c65..51e5939 100644 --- a/lib/pipey/chain.rb +++ b/lib/pipey/chain.rb @@ -4,13 +4,13 @@ module Pipey class Chain < SimpleDelegator include Core - def self.call(initial, params = {}) - new(initial).call(params) + def self.call(initial, **params) + new(initial).call(**params) end - def call!(params = {}) # :nodoc: - self.class.steps_for(params).each do |name| - result = send(name, params) + def call!(**params) + self.class.steps_for(**params).each do |name| + result = send(name, **params) if self.class.valid_pipe_result?(result) __setobj__(result) diff --git a/lib/pipey/core.rb b/lib/pipey/core.rb index a18dc6b..adc3150 100644 --- a/lib/pipey/core.rb +++ b/lib/pipey/core.rb @@ -10,13 +10,13 @@ def valid_pipe_result?(_) end end - def stop!(*args) - throw(:__pipey_stop, *args) + def stop!(*args, **kwargs) + throw(:__pipey_stop, *args, **kwargs) end - def call(*args) + def call(**args) catch :__pipey_stop do - clone.call!(*args) + clone.call!(**args) end end end diff --git a/lib/pipey/extensions.rb b/lib/pipey/extensions.rb index 6d758bf..6bb0f62 100644 --- a/lib/pipey/extensions.rb +++ b/lib/pipey/extensions.rb @@ -3,7 +3,7 @@ module Extensions module RequiredKeys # @override Pipey::DSL.steps_for # @override Pipey::Scanner.steps_for - def steps_for(params) + def steps_for(**params) super.reject do |step| instance_method(step).parameters.any? do |type, name| type == :keyreq && params[name].nil? diff --git a/lib/pipey/line.rb b/lib/pipey/line.rb index 6ee587a..2c10508 100644 --- a/lib/pipey/line.rb +++ b/lib/pipey/line.rb @@ -4,13 +4,13 @@ module Pipey class Line include Core - def self.call(*args) - new.call(*args) + def self.call(initial, **opts) + new.call!(initial, **opts) end - def call!(initial, opts = {}) - self.class.steps_for(opts).reduce(initial) do |value, name| - result = send(name, value, opts) + def call!(initial, **opts) + self.class.steps_for(**opts).reduce(initial) do |value, name| + result = send(name, value, **opts) if self.class.valid_pipe_result?(result) result diff --git a/lib/pipey/steps.rb b/lib/pipey/steps.rb index d20cf59..2d8c4f8 100644 --- a/lib/pipey/steps.rb +++ b/lib/pipey/steps.rb @@ -5,7 +5,7 @@ def steps @steps ||= [] end - def steps_for(_) + def steps_for(**_) steps end @@ -24,7 +24,7 @@ def initialize(pattern) instance_methods.grep(pattern) end - define_method :steps_for do |_| + define_method :steps_for do |**_| steps end end diff --git a/pipey.gemspec b/pipey.gemspec index 4a7b934..a4b8736 100644 --- a/pipey.gemspec +++ b/pipey.gemspec @@ -19,8 +19,7 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] - spec.add_development_dependency "bundler", "~> 1.14" - spec.add_development_dependency "rake", "~> 10.0" + spec.add_development_dependency "rake" spec.add_development_dependency "minitest" spec.add_development_dependency "m" end diff --git a/test/pipey/chain_test.rb b/test/pipey/chain_test.rb index 4b66133..042643f 100644 --- a/test/pipey/chain_test.rb +++ b/test/pipey/chain_test.rb @@ -42,10 +42,7 @@ def run_stop(**) def test_line_with_dsl s = Subject::DSL - assert_equal [:run_multiply, :run_divide], s.steps - assert_equal [:run_multiply, :run_divide], s.steps_for(multiply_by: 10) - assert_equal [2, 4], s.call([1, 2], multiply_by: 10, divide_by: 5) end diff --git a/test/pipey/line_test.rb b/test/pipey/line_test.rb index 9c55d98..ebee916 100644 --- a/test/pipey/line_test.rb +++ b/test/pipey/line_test.rb @@ -40,7 +40,7 @@ def run_two(input, divide_by:, **) class Stopper < Pipey::Chain extend Pipey::Steps::Scanner[/^run_/] - def run_stop(_, **) + def run_stop(**) stop! 100 200 end @@ -48,7 +48,7 @@ def run_stop(_, **) def test_line_with_dsl assert_equal [:run_multiply, :run_divide], Subject::DSL.steps - assert_equal 2, Subject::DSL.call(1) + assert_equal 2, Subject::DSL.call(1, multiply_by: 10) end def test_line_with_scanner