activestorage-delayed 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0039f175e4f3348c3a168c81529baab2cd200eb75bbf69e7470d73d05d1c3336'
4
- data.tar.gz: 972e99f9f1a92ad432abfbf950b45f1f14542b0b9fbfadfe979038da40fd92e2
3
+ metadata.gz: d3378c0e2948f1f326f736c4ef7947dea58df8f4f6a0be0db293b8b12211f9aa
4
+ data.tar.gz: 309c3e54d9bf480a289bafe6bb22820cb25fb298610fde2b2171be45ee39340a
5
5
  SHA512:
6
- metadata.gz: b2c43d55f3eb96fc53b14d5c60d25b1b7cd600181a359b5d32e0b25366bba7e6e738398cc6f44f4e089c328d05a4b53d19d96479a58dfc795d1f52bb33a1156c
7
- data.tar.gz: 470a6b3ed0cc27e7a86efb5678644e919b8c0118c2c81cd7b678b485b9d0551852dd4480b85bb82f1e14bcd6482121aaa96b027ebf974c838461c42c165e3447
6
+ metadata.gz: d71f44517ca41a2ce2f093187ecced04afccbe864e1999223c310207c383a7980abb983339264a68c67966e48bff113c383ced0f4abc7ff1d25a68f1d5d32000
7
+ data.tar.gz: 85f7a2fad1f398c7354ba1d5c5b2f946d3b939af6ce0d1135c5e8ade4664df94a30e8148f8c5d2a9ce4d90f3e066558bdfdbfc18468b8612bbea7f8403ffa3e4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- activestorage-delayed (0.2.0)
4
+ activestorage-delayed (0.3.3)
5
5
  activestorage
6
6
  rails
7
7
 
@@ -13,24 +13,25 @@ module ActivestorageDelayed
13
13
  return unless delayed_upload
14
14
 
15
15
  remove_files
16
- upload_photos
17
- save_changes
16
+ save_changes if upload_photos
18
17
  end
19
18
 
20
19
  private
21
20
 
22
21
  def upload_photos
23
- tmp_files_data.each(&method(:upload_photo))
22
+ tmp_files_data.map(&method(:upload_photo)).all?
24
23
  end
25
24
 
26
25
  def upload_photo(file_data)
27
26
  parse_file_io(file_data) do |io|
28
27
  file_data['io'] = io
28
+ remove_duplicated_object(file_data['key']) if file_data['key']
29
29
  model.send(attr_name).attach(file_data.transform_keys(&:to_sym))
30
30
  model.send("#{attr_name}_after_upload", file_data)
31
31
  end
32
+ true
32
33
  rescue => e # rubocop:disable Style/RescueStandardError
33
- print_failure(e, file_data)
34
+ print_failure(e, file_data) && false
34
35
  end
35
36
 
36
37
  def print_failure(error, file_data = {})
@@ -72,9 +73,11 @@ module ActivestorageDelayed
72
73
  # @param io [StringIO, File]
73
74
  # @param variant_info [Hash, Nil] ActiveStorage variant info. Sample: { resize_to_fit: [400, 400], convert: 'jpg' }
74
75
  def transform_variation(io, variant_info, &block)
75
- return block.call(io) unless variant_info
76
+ variant_info ? ActiveStorage::Variation.wrap(variant_info).transform(io, &block) : block.call(io)
77
+ end
76
78
 
77
- ActiveStorage::Variation.wrap(variant_info).transform(io, &block)
79
+ def remove_duplicated_object(key)
80
+ ActiveStorage::Blob.where(key: key).take&.destroy!
78
81
  end
79
82
 
80
83
  def model
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivestorageDelayed
4
- VERSION = '0.3.3'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activestorage-delayed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Owen Peredo Diaz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage