You've already forked image_processing
mirror of
https://github.com/usetrmnl/image_processing.git
synced 2026-04-29 13:33:11 -07:00
59ce62b703
Ruby 2.7 introduced warnings around implicit conversions between
kwargs and hashes, so we fix the warnings.
If we have the following method:
def foo(a, b, **c)
end
And we pass arguments like this:
args = [1, 2, { x: :y }]
foo(*args)
This will trigger a kwarg warning on Ruby 2.7. So, we need to explicitly
pass the last argument as kwargs if it is a hash.
Surprisingly, the warning was only triggered when using #apply:
# would trigger the kwargs warning
ImageProcessing::Vips
.source("/path/to/image")
.apply!(resize_to_limit: [400, 400, sharpen: false])
And not when calling operation directly:
# wouldn't trigger the kwargs warning
ImageProcessing::Vips
.source("/path/to/image")
.resize_to_limit!(400, 400, sharpen: false)
Even though final options are exactly the same, so the code that's then
executed on processing should be the same.
options1 = ImageProcessing::Vips
.apply(resize_to_limit: [400, 400, sharpen: false])
options2 = ImageProcessing::Vips
.resize_to_limit(400, 400, sharpen: false)
options1 == options2 #=> true
The warning was coming from Processor.apply_operation when we would call
an underlying macro. It's probably a bug in Ruby, both examples should have
triggered the same warning. But I couldn't isolate it, so instead we
add an additional test case for #apply.
Co-authored-by: Janko Marohnić <janko.marohnic@gmail.com>