From 109b82ad192d728fe21228b194f0f597049477a9 Mon Sep 17 00:00:00 2001 From: Vasily Fedoseyev Date: Thu, 9 May 2024 23:12:03 +0300 Subject: [PATCH 1/2] Test on ruby 3.3 --- .github/workflows/test.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 733868b..972fe70 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -13,7 +13,9 @@ jobs: include: - ruby-version: 3.2.3 rails-version: 70 - - ruby-version: 3.2.3 + - ruby-version: 3.3.1 + rails-version: 70 + - ruby-version: 3.3.1 rails-version: 71 env: From b638a435e14389dcc0c1c143a980125fda50b978 Mon Sep 17 00:00:00 2001 From: Vasily Fedoseyev Date: Thu, 9 May 2024 23:17:06 +0300 Subject: [PATCH 2/2] Tempfile#size patch was broken on ruby 3.3, also fix rubocop --- lib/paperclip/iostream.rb | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/lib/paperclip/iostream.rb b/lib/paperclip/iostream.rb index 1ad335b..0e8bc28 100644 --- a/lib/paperclip/iostream.rb +++ b/lib/paperclip/iostream.rb @@ -1,10 +1,18 @@ +# frozen_string_literal: true + # Provides method that can be included on File-type objects (IO, StringIO, Tempfile, etc) to allow stream copying # and Tempfile conversion. module IOStream # Returns a Tempfile containing the contents of the readable object. def to_tempfile(object) return object.to_tempfile if object.respond_to?(:to_tempfile) - name = object.respond_to?(:original_filename) ? object.original_filename : (object.respond_to?(:path) ? object.path : "stream") + name = if object.respond_to?(:original_filename) + object.original_filename + elsif object.respond_to?(:path) + object.path + else + "stream" + end tempfile = Tempfile.new(["ppc-iostream", File.extname(name)]) tempfile.binmode stream_to(object, tempfile) @@ -13,32 +21,15 @@ module IOStream # Copies one read-able object from one place to another in blocks, obviating the need to load # the whole thing into memory. Defaults to 8k blocks. Returns a File if a String is passed # in as the destination and returns the IO or Tempfile as passed in if one is sent as the destination. - def stream_to object, path_or_file, in_blocks_of = 8192 + def stream_to(object, path_or_file, in_blocks_of = 8192) dstio = case path_or_file when String then File.new(path_or_file, "wb+") when IO, Tempfile then path_or_file end - buffer = "" + buffer = +"" object.rewind - while object.read(in_blocks_of, buffer) do - dstio.write(buffer) - end + dstio.write(buffer) while object.read(in_blocks_of, buffer) dstio.rewind dstio end end - -# Corrects a bug in Windows when asking for Tempfile size. -if defined?(Tempfile) && RUBY_PLATFORM !~ /java/ - class Tempfile - def size - if @tmpfile - @tmpfile.fsync - @tmpfile.flush - @tmpfile.stat.size - else - 0 - end - end - end -end