From cf7ecfefd1f27571f9af459deea85a3afd75cb53 Mon Sep 17 00:00:00 2001 From: Mattia Roccoberton Date: Sun, 15 Mar 2026 10:45:59 +0100 Subject: [PATCH] chore: Replace Rails version control line Replace Gem::Version.new(Rails.version) >= Gem::Version.new("7.1") with Rails::VERSION::MAJOR/MINOR integer comparison. This avoids allocating two Gem::Version objects on every failed upload and is consistent with how the rest of the gem does version branching. --- app/controllers/active_storage_db/files_controller.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/app/controllers/active_storage_db/files_controller.rb b/app/controllers/active_storage_db/files_controller.rb index 5687f44..bd6ae7c 100644 --- a/app/controllers/active_storage_db/files_controller.rb +++ b/app/controllers/active_storage_db/files_controller.rb @@ -28,7 +28,8 @@ def update private def acceptable_content?(token) - token[:content_type] == request.content_mime_type && token[:content_length] == request.content_length + token[:content_type] == request.content_mime_type && + token[:content_length] == request.content_length end def db_service @@ -53,7 +54,7 @@ def serve_file(key, content_type:, disposition:) send_data(db_service.download(key), options) end - def upload_file(token, body:) + def upload_file(token, body:) # rubocop:disable Naming/PredicateMethod return false unless acceptable_content?(token) db_service.upload(token[:key], request.body, checksum: token[:checksum]) @@ -61,7 +62,11 @@ def upload_file(token, body:) end def unprocessable - Gem::Version.new(Rails.version) >= Gem::Version.new("7.1") ? :unprocessable_content : :unprocessable_entity + if Rails::VERSION::MAJOR > 7 || (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR >= 1) + :unprocessable_content + else + :unprocessable_entity + end end end end