about summary refs log tree commit diff
path: root/lib/paperclip/attachment_extensions.rb
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-03-28 15:19:05 +0100
committerGitHub <noreply@github.com>2020-03-28 15:19:05 +0100
commita192b193bdf7013df09c6cd63916274cd9d47cf7 (patch)
tree413de2a72a6f3a126e19e12178524ca33c27e436 /lib/paperclip/attachment_extensions.rb
parent02f1c04fabab221130de8dfb5611be81825b193b (diff)
parentd98fabf2ee44c2c25775066abda46552ab05993e (diff)
Merge pull request #1308 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'lib/paperclip/attachment_extensions.rb')
-rw-r--r--lib/paperclip/attachment_extensions.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/paperclip/attachment_extensions.rb b/lib/paperclip/attachment_extensions.rb
index 3b308af5f..d9ec0159a 100644
--- a/lib/paperclip/attachment_extensions.rb
+++ b/lib/paperclip/attachment_extensions.rb
@@ -24,6 +24,19 @@ module Paperclip
         flush_deletes
       end
     end
+
+    def variant?(other_filename)
+      return true  if original_filename == other_filename
+      return false if original_filename.nil?
+
+      formats = styles.values.map(&:format).compact
+
+      return false if formats.empty?
+
+      other_extension = File.extname(other_filename)
+
+      formats.include?(other_extension.delete('.')) && File.basename(other_filename, other_extension) == File.basename(original_filename, File.extname(original_filename))
+    end
   end
 end