better_record 0.19.0 → 0.19.1
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: 6f5322959bf87be1c0bb13ca7f5b72c71566023bb790006e5980bb8c0b59cd88
|
4
|
+
data.tar.gz: 9f58c4bae300c5451ef78fd566e90578f1fb741c9b36da9236ab4551169ee545
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba2d95d83eea2ea992b2a190331259553e778ac08999b63d19c27dab614ddf08302f9f08786088ef76b4957a1b92b5ecd39ef3b5b78d258f3f790948438d843b
|
7
|
+
data.tar.gz: 55193234a82cfacfa2a85771b6c516bf44f8b610fec7baf8d322aaf30fcebff46aed0634611a2fa418a30d5d80ebb9c964d8f6d752e1c7654cb8b95489f1523e
|
@@ -5,18 +5,29 @@ module BetterRecord
|
|
5
5
|
def perform(**params)
|
6
6
|
begin
|
7
7
|
if record = params[:model].constantize.find_by(params[:query].deep_symbolize_keys)
|
8
|
-
|
8
|
+
name = params[:attachment].to_sym
|
9
|
+
blob = record.__send__(name).blob
|
9
10
|
tmp = Tempfile.new
|
10
11
|
tmp.binmode
|
11
|
-
tmp.write(blob.service.download(blob.variant(blob.filename.to_s =~ /-resized
|
12
|
+
tmp.write(blob.service.download(blob.variant(blob.filename.to_s =~ /-resized/ ? {resize: '70%'} : params[:options]).processed.key))
|
12
13
|
tmp.flush
|
13
14
|
tmp.rewind
|
14
|
-
|
15
|
-
|
15
|
+
|
16
|
+
blob.analyze if blob.filename.to_s =~ /-resized/
|
17
|
+
|
18
|
+
attachment = ActionDispatch::Http::UploadedFile.new(
|
19
|
+
tempfile: tmp,
|
16
20
|
filename: blob.filename.to_s.sub(/(\.[^.]*)$/, '-resized\1').sub(/(-resized)+/, '-resized'),
|
17
|
-
|
21
|
+
type: blob.content_type
|
18
22
|
)
|
19
|
-
|
23
|
+
|
24
|
+
record.
|
25
|
+
__send__ :delete_attachment, name, true
|
26
|
+
|
27
|
+
record.
|
28
|
+
reload.__send__(params[:attachment]).
|
29
|
+
reload.attach(attachment)
|
30
|
+
|
20
31
|
puts "\n\nSAVED IMAGE\n\n"
|
21
32
|
begin
|
22
33
|
if params[:backup_action].present?
|
@@ -25,10 +25,11 @@ module BetterRecord
|
|
25
25
|
# == Class Methods ========================================================
|
26
26
|
def self.set_audit_methods!
|
27
27
|
begin
|
28
|
-
|
28
|
+
t_name = BetterRecord::LoggedAction.table_name.sub('_view', '')
|
29
|
+
connection.execute(%Q(SELECT 1 FROM #{t_name}_#{self.table_name} LIMIT 1))
|
29
30
|
|
30
31
|
self.const_set(:LoggedAction, Class.new(ApplicationRecord))
|
31
|
-
self.const_get(:LoggedAction).table_name = "#{
|
32
|
+
self.const_get(:LoggedAction).table_name = "#{t_name}_#{self.table_name}"
|
32
33
|
rescue ActiveRecord::StatementInvalid
|
33
34
|
self.const_set(:LoggedAction, BetterRecord::LoggedAction)
|
34
35
|
end
|
@@ -143,19 +143,8 @@ module BetterRecord
|
|
143
143
|
define_method :"copy_#{avatar_name}" do |from = avatar_name, to = :"last_#{avatar_name}"|
|
144
144
|
puts "COPYING #{from} TO #{to}"
|
145
145
|
from_attachment = __send__ from
|
146
|
-
to_attachment = __send__ to
|
147
146
|
|
148
|
-
|
149
|
-
begin
|
150
|
-
atch = ActiveStorage::Attachment.find_by(to_attachment.id)
|
151
|
-
atch&.purge_later
|
152
|
-
rescue Exception
|
153
|
-
begin
|
154
|
-
ActiveStorage::Attachment.find_by(to_attachment.id).destroy
|
155
|
-
rescue Exception
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
147
|
+
delete_attachment to
|
159
148
|
|
160
149
|
if from_attachment.attached?
|
161
150
|
tmp = Tempfile.new
|
@@ -168,12 +157,33 @@ module BetterRecord
|
|
168
157
|
from_attachment = r.__send__ from
|
169
158
|
to_attachment = r.__send__ to
|
170
159
|
|
171
|
-
to_attachment.attach(
|
160
|
+
to_attachment.attach(
|
161
|
+
ActionDispatch::Http::UploadedFile.new(
|
162
|
+
tempfile: tmp,
|
163
|
+
filename: from_attachment.filename.to_s,
|
164
|
+
type: from_attachment.content_type
|
165
|
+
)
|
166
|
+
)
|
172
167
|
tmp.close
|
173
168
|
end
|
174
169
|
true
|
175
170
|
end
|
176
171
|
|
172
|
+
define_method :delete_attachment do |att_name = avatar_name, now = false|
|
173
|
+
atchd = __send__ att_name
|
174
|
+
if atchd.attached?
|
175
|
+
begin
|
176
|
+
atch = ActiveStorage::Attachment.find_by(atchd.id)
|
177
|
+
atch&.__send__ now ? :purge : :purge_later
|
178
|
+
rescue Exception
|
179
|
+
begin
|
180
|
+
ActiveStorage::Attachment.find_by(atchd.id).destroy
|
181
|
+
rescue Exception
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
177
187
|
define_method :reloaded_record do
|
178
188
|
self.class.find_by(id: self.id)
|
179
189
|
end
|