Ruby 3.0+

This commit is contained in:
Luca Guidi 2022-01-13 23:27:51 +01:00
parent 02204b638e
commit 28a7bc6455
No known key found for this signature in database
GPG Key ID: 15BF83DA8F3991A0
7 changed files with 26 additions and 79 deletions

View File

@ -24,9 +24,8 @@ jobs:
fail-fast: false
matrix:
ruby:
- "3.1"
- "3.0"
- "2.7"
- "2.6"
steps:
- uses: actions/checkout@v1
- name: Install package dependencies

View File

@ -181,18 +181,10 @@ module Hanami
# # ...
# end
# end
if RUBY_VERSION >= "3.0"
def initialize(*args, **kwargs)
super
ensure
@__result = ::Hanami::Interactor::Result.new
end
else
def initialize(*args)
super
ensure
@__result = ::Hanami::Interactor::Result.new
end
def initialize(*args, **kwargs)
super
ensure
@__result = ::Hanami::Interactor::Result.new
end
# Triggers the operation and return a result.
@ -361,51 +353,27 @@ module Hanami
# end
#
# Signup.new.call # => NoMethodError
if RUBY_VERSION >= "3.0"
def call(*args, **kwargs)
@__result = ::Hanami::Interactor::Result.new
_call(*args, **kwargs) { super }
end
else
def call(*args)
@__result = ::Hanami::Interactor::Result.new
_call(*args) { super }
end
def call(*args, **kwargs)
@__result = ::Hanami::Interactor::Result.new
_call(*args, **kwargs) { super }
end
private
# @api private
# @since 1.1.0
if RUBY_VERSION >= "3.0"
def _call(*args, **kwargs)
catch :fail do
validate!(*args, **kwargs)
yield
end
_prepare!
def _call(*args, **kwargs)
catch :fail do
validate!(*args, **kwargs)
yield
end
else
def _call(*args)
catch :fail do
validate!(*args)
yield
end
_prepare!
end
_prepare!
end
# @since 1.1.0
if RUBY_VERSION >= "3.0"
def validate!(*args, **kwargs)
fail! unless valid?(*args, **kwargs)
end
else
def validate!(*args)
fail! unless valid?(*args)
end
def validate!(*args, **kwargs)
fail! unless valid?(*args, **kwargs)
end
end

View File

@ -293,16 +293,9 @@ class CreateUser
include Hanami::Interactor
expose :user
if RUBY_VERSION >= "3.0"
def call(**params)
build_user(**params)
persist
end
else
def call(**params)
build_user(params)
persist
end
def call(**params)
build_user(**params)
persist
end
private

View File

@ -210,7 +210,7 @@ RSpec.describe Hanami::Utils::Hash do
describe ".deep_serialize" do
let(:input) do
klass = Class.new(OpenStruct) do
klass = Class.new(OpenStruct) do # rubocop:disable Style/OpenStructUse
def to_hash
to_h
end

View File

@ -1319,14 +1319,8 @@ RSpec.describe Hanami::Utils::Kernel do
describe "when a big decimal is given" do
let(:input) { BigDecimal(7944.2343, 10) }
if RUBY_VERSION >= "2.4"
it "returns the string representation" do
expect(@result).to eq "0.79442343e4"
end
else
it "returns the string representation" do
expect(@result).to eq "0.79442343E4"
end
it "returns the string representation" do
expect(@result).to eq "0.79442343e4"
end
end
@ -1459,16 +1453,9 @@ RSpec.describe Hanami::Utils::Kernel do
end
describe "when a class is given" do
if RUBY_VERSION >= "2.4"
let(:input) { Integer }
it "returns the string representation" do
expect(@result).to eq "Integer"
end
else
let(:input) { Fixnum } # rubocop:disable Lint/UnifiedInteger
it "returns the string representation" do
expect(@result).to eq "Fixnum"
end
let(:input) { Integer }
it "returns the string representation" do
expect(@result).to eq "Integer"
end
end

View File

@ -49,7 +49,7 @@ RSpec.describe Hanami::Utils::LoadPaths do
it "raises an error if a path is unknown" do
paths = Hanami::Utils::LoadPaths.new "unknown/path"
expect { paths.each {} }.to raise_error(Errno::ENOENT)
expect { paths.each }.to raise_error(Errno::ENOENT)
end
end

View File

@ -52,7 +52,7 @@ RSpec.describe Hanami::Utils::String do
it "raises error when try to apply unknown transformation" do
input = "Sakura"
expect { Hanami::Utils::String.transform(input, :unknown) }.to raise_error(NoMethodError, %(undefined method `:unknown' for "Sakura":String))
expect { Hanami::Utils::String.transform(input, :unknown) }.to raise_error(NoMethodError)
end
it "raises error when given proc has arity not equal to 1" do