better_record 0.15.1 → 0.15.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d1f355a28bcc6fa75e43137e4f6d2096c78b85de3420733cf201826424e22d
|
4
|
+
data.tar.gz: d5da519726817d407cc67a027041dc0c258daf715f6c8675de934cda2c3b626b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2cdb3aeac811064a91c3450942a5e5f0776e539aba2300a14c2ec7f2883caaf985d745e44a0dfaa5761ed794a0ba37322e2583c5d014435c5e5364852799c223
|
7
|
+
data.tar.gz: 7e965a6f43b3fb45b47ab026d682bf00294ec8b417077183189d85c39f965d247eb6a83d90e6d3a0e59c2194e4aa938a1c1d7a748262962a64fef211be494892
|
@@ -13,20 +13,35 @@ module BetterRecord
|
|
13
13
|
tmp.rewind
|
14
14
|
record.__send__(params[:attachment]).attach(
|
15
15
|
io: tmp,
|
16
|
-
filename: blob.filename,
|
16
|
+
filename: blob.filename.to_s.sub(/(\.[^.]*)$/, '-resized\1'),
|
17
17
|
content_type: blob.content_type
|
18
18
|
)
|
19
|
+
tmp.close
|
20
|
+
puts "\n\nSAVED IMAGE\n\n"
|
19
21
|
begin
|
20
|
-
|
22
|
+
if params[:backup_action].present?
|
23
|
+
record.class.find_by(params[:query]).__send__(params[:backup_action].to_sym)
|
24
|
+
end
|
21
25
|
rescue
|
26
|
+
puts "BACKUP ACTION FAILED"
|
27
|
+
puts $!.message
|
28
|
+
puts $!.backtrace
|
22
29
|
end
|
23
|
-
|
30
|
+
begin
|
31
|
+
puts "\n\n PURGING BLOB \n\n"
|
32
|
+
puts "blob exists? #{blob = ActiveStorage::Blob.find_by(id: blob.id).present?}"
|
33
|
+
blob.purge if blob.present?
|
34
|
+
puts "\n\n FINISHED PURGING BLOB \n\n"
|
35
|
+
rescue
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise ActiveRecord::RecordNotFound
|
24
39
|
end
|
25
|
-
true
|
40
|
+
return true
|
26
41
|
rescue
|
27
|
-
|
28
|
-
|
29
|
-
|
42
|
+
"ERROR RESIZING IMAGE"
|
43
|
+
puts $!.message
|
44
|
+
puts $!.backtrace.first(25)
|
30
45
|
return false
|
31
46
|
end
|
32
47
|
end
|
@@ -16,7 +16,6 @@ module BetterRecord
|
|
16
16
|
min_image_size: nil,
|
17
17
|
max_image_size: 500.kilobytes,
|
18
18
|
shrink_large_image: false,
|
19
|
-
shrink_later: false,
|
20
19
|
**opts
|
21
20
|
)
|
22
21
|
# == Constants ============================================================
|
@@ -61,22 +60,14 @@ module BetterRecord
|
|
61
60
|
define_method :valid_image_size do
|
62
61
|
if max_image_size && __send__(avatar_name).blob.byte_size > max_image_size
|
63
62
|
if shrink_large_image.present?
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
backup_action: "cache_current_#{avatar_name}",
|
73
|
-
options: shrink_large_image
|
74
|
-
}
|
75
|
-
rescue
|
76
|
-
puts $!.message
|
77
|
-
puts $!.backtrace
|
78
|
-
return false
|
79
|
-
end
|
63
|
+
@copy_later = true
|
64
|
+
ResizeBlobImageJob.perform_later(
|
65
|
+
model: self.class.to_s,
|
66
|
+
query: {id: self.id},
|
67
|
+
attachment: avatar_name.to_s,
|
68
|
+
backup_action: image_validator.to_s,
|
69
|
+
options: shrink_large_image
|
70
|
+
)
|
80
71
|
else
|
81
72
|
errors.add(avatar_name, "is too large, maximum #{ActiveSupport::NumberHelper.number_to_human_size(max_image_size)}")
|
82
73
|
return false
|
@@ -89,12 +80,17 @@ module BetterRecord
|
|
89
80
|
end
|
90
81
|
|
91
82
|
define_method :valid_image do
|
92
|
-
return unless __send__(avatar_name).attached?
|
83
|
+
return true unless __send__(avatar_name).attached?
|
93
84
|
|
94
85
|
if valid_image_format && valid_image_size
|
95
|
-
|
86
|
+
return true if @copy_later
|
87
|
+
puts "\n\nCOPYING AVATAR\n\n"
|
88
|
+
result = self.class.find_by(id: self.id).__send__(:"cache_current_#{avatar_name}")
|
89
|
+
puts "\n\nDONE COPYING AVATAR: #{result}\n\n"
|
90
|
+
result
|
96
91
|
else
|
97
|
-
|
92
|
+
r = self.find_by(id: self.id).__send__(avatar_name)
|
93
|
+
r.purge if r.attached?
|
98
94
|
__send__(:"load_last_#{avatar_name}") if __send__(:"last_#{avatar_name}").attached?
|
99
95
|
false
|
100
96
|
end
|
@@ -109,18 +105,23 @@ module BetterRecord
|
|
109
105
|
end
|
110
106
|
|
111
107
|
define_method :"copy_#{avatar_name}" do |from = avatar_name, to = :"last_#{avatar_name}"|
|
112
|
-
from
|
113
|
-
|
108
|
+
puts "COPYING #{from} TO #{to}"
|
109
|
+
from_attachment = __send__ from
|
110
|
+
to_attachment = __send__ to
|
114
111
|
|
115
|
-
purge(
|
112
|
+
purge(to_attachment) if to_attachment.attached?
|
116
113
|
|
117
114
|
tmp = Tempfile.new
|
118
115
|
tmp.binmode
|
119
|
-
tmp.write(
|
116
|
+
tmp.write(from_attachment.download)
|
120
117
|
tmp.flush
|
121
118
|
tmp.rewind
|
122
119
|
|
123
|
-
|
120
|
+
r = self.class.find_by(id: self.id)
|
121
|
+
from_attachment = r.__send__ from
|
122
|
+
to_attachment = r.__send__ to
|
123
|
+
|
124
|
+
to_attachment.attach(io: tmp, filename: from_attachment.filename, content_type: from_attachment.content_type)
|
124
125
|
tmp.close
|
125
126
|
true
|
126
127
|
end
|