From 44a6c6fa43b308dd184d6ee9e2779a38acf7f546 Mon Sep 17 00:00:00 2001 From: Mth0158 Date: Sun, 8 Dec 2024 17:14:57 +0100 Subject: [PATCH] [Analyzer] Do not load image analyzer gem if already loaded --- .../analyzer/image_analyzer/image_magick.rb | 2 +- lib/active_storage_validations/analyzer/image_analyzer/vips.rb | 2 +- test/analyzers/image_analyzers/image_magick_test.rb | 2 ++ test/analyzers/image_analyzers/vips_test.rb | 2 ++ 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb b/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb index 47b80a8..40f3dcf 100644 --- a/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb +++ b/lib/active_storage_validations/analyzer/image_analyzer/image_magick.rb @@ -10,7 +10,7 @@ class Analyzer::ImageAnalyzer::ImageMagick < Analyzer::ImageAnalyzer def read_image begin - require "mini_magick" + require "mini_magick" unless Object.const_defined?(:MiniMagick) rescue LoadError logger.info "Skipping image analysis because the mini_magick gem isn't installed" return {} diff --git a/lib/active_storage_validations/analyzer/image_analyzer/vips.rb b/lib/active_storage_validations/analyzer/image_analyzer/vips.rb index 3fd017e..ef60489 100644 --- a/lib/active_storage_validations/analyzer/image_analyzer/vips.rb +++ b/lib/active_storage_validations/analyzer/image_analyzer/vips.rb @@ -9,7 +9,7 @@ class Analyzer::ImageAnalyzer::Vips < Analyzer::ImageAnalyzer def read_image begin - require "ruby-vips" + require "ruby-vips" unless Object.const_defined?(:Vips) rescue LoadError logger.info "Skipping image analysis because the ruby-vips gem isn't installed" return {} diff --git a/test/analyzers/image_analyzers/image_magick_test.rb b/test/analyzers/image_analyzers/image_magick_test.rb index 566ab60..ec31f86 100644 --- a/test/analyzers/image_analyzers/image_magick_test.rb +++ b/test/analyzers/image_analyzers/image_magick_test.rb @@ -4,6 +4,8 @@ require 'analyzers/support/analyzer_helpers' require 'analyzers/image_analyzers/shared_examples/returns_the_right_metadata_for_any_attachable' +return unless Object.const_defined?(:MiniMagick) + describe ActiveStorageValidations::Analyzer::ImageAnalyzer::ImageMagick do include AnalyzerHelpers diff --git a/test/analyzers/image_analyzers/vips_test.rb b/test/analyzers/image_analyzers/vips_test.rb index e7e048f..223a12c 100644 --- a/test/analyzers/image_analyzers/vips_test.rb +++ b/test/analyzers/image_analyzers/vips_test.rb @@ -4,6 +4,8 @@ require 'analyzers/support/analyzer_helpers' require 'analyzers/image_analyzers/shared_examples/returns_the_right_metadata_for_any_attachable' +return unless Object.const_defined?(:Vips) + describe ActiveStorageValidations::Analyzer::ImageAnalyzer::Vips do include AnalyzerHelpers