Skip to content

Commit f97cb7c

Browse files
committed
Fix: ActiveStorage with non-Disk Storage
1 parent b772049 commit f97cb7c

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

lib/image_quality_check/determine_quality.rb

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def initialize(model, column_name, tmp_file = nil)
1616
def run(&block)
1717
unless @tmp_file
1818
@tmp_file = Tempfile.new(['image_quality'])
19+
@tmp_file.bin_mode
1920
unless read!(@tmp_file)
2021
result = {
2122
quality: 0,
@@ -63,11 +64,21 @@ def determine_quality
6364
def read!(tmp_file)
6465
case @column.class.to_s
6566
when 'ActiveStorage::Attached::One'
66-
if !@column.blob || !File.exist?(@column.blob.service.send(:path_for, @column.blob.key))
67-
false
67+
if @column.blob.service.respond_to?(:path_for)
68+
if !@column.blob || !File.exist?(@column.blob.service.send(:path_for, @column.blob.key))
69+
false
70+
else
71+
FileUtils.cp(@column.blob.service.send(:path_for, @column.blob.key), tmp_file.path)
72+
true
73+
end
6874
else
69-
FileUtils.cp(@column.blob.service.send(:path_for, @column.blob.key), tmp_file.path)
70-
true
75+
if !@column.blob || !@column.blob.attached?
76+
false
77+
else
78+
tmp_file.write(@column.download)
79+
tmp_file.rewind
80+
true
81+
end
7182
end
7283
when "Paperclip::Attachment"
7384
if @column.options[:storage] == :s3

lib/image_quality_check/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module ImageQualityCheck
2-
VERSION = "0.4.0"
2+
VERSION = "0.4.1"
33
end

0 commit comments

Comments
 (0)