activestorage-delayed 0.2.0 → 0.3.0

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: 23b95115e89560a1c7e3a880f0b89a1d7aaf99fe4b6e54c1b207ce0d435dfda2
4
- data.tar.gz: 727dd8e29453607c884e4ddf126fd1f41da790bb8c1db89ae30cedc506b02900
3
+ metadata.gz: 621bd6e1ad3690b81dfcd6d12ef466046db31741cca14fb529a6d0c0f6fb4089
4
+ data.tar.gz: ef77110cf9d92f5247f2bff431bb2f89507d69709001c063cf3db0ffa017a2ec
5
5
  SHA512:
6
- metadata.gz: 976b9b1c03bab65f651fb81d2915aeb9561e380fbd35b26069c3263d4f443f029cc4fd22bee015a4e946eb20487b68228a5d66d175978c556f0a76e6979b59b8
7
- data.tar.gz: 29d8ae5308daa56f5845e4deeb70a709cce48a9f5c48b2759ad4473cea0041c6a84a0f50b50657235177d5d10dd6736696c305a304d38474dc2cca05d5a6de5b
6
+ metadata.gz: add4b74f833f2dc0c3a39a82c7750cdb1a38d4d1ef98abc9affd3189e8f010d82d495c03452edb5c502e06938abd64ab7bfd40b8d6ce4b1eee514bcb18d7d2c8
7
+ data.tar.gz: 372c5fe7906804d59a60281a130e6f697a21a96644ae592622b0a1dbe69c4b5943aaf9006958f804800c95190c45ef15a61d91ba6595b6901a7b5e9e5258ab75
@@ -10,40 +10,63 @@
10
10
  <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
11
  <excludeFolder url="file://$MODULE_DIR$/spec/dummy/tmp/cache" />
12
12
  </content>
13
- <orderEntry type="jdk" jdkName="Remote: ruby-2.5.9-p229" jdkType="RUBY_SDK" />
13
+ <orderEntry type="jdk" jdkName="Remote: ruby-3.1.1-p18" jdkType="RUBY_SDK" />
14
14
  <orderEntry type="sourceFolder" forTests="false" />
15
- <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, Remote: ruby-2.5.9-p229) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, Remote: ruby-2.5.9-p229) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.10, Remote: ruby-2.5.9-p229) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.10, Remote: ruby-2.5.9-p229) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, Remote: ruby-2.5.9-p229) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="erubi (v1.10.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="factory_bot (v6.2.1, Remote: ruby-2.5.9-p229) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="factory_bot_rails (v6.2.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
24
- <orderEntry type="library" scope="PROVIDED" name="globalid (v1.0.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
25
- <orderEntry type="library" scope="PROVIDED" name="i18n (v1.10.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="mail (v2.7.1, Remote: ruby-2.5.9-p229) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="marcel (v1.0.2, Remote: ruby-2.5.9-p229) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="mini_mime (v1.1.2, Remote: ruby-2.5.9-p229) [gem]" level="application" />
30
- <orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="nio4r (v2.5.8, Remote: ruby-2.5.9-p229) [gem]" level="application" />
32
- <orderEntry type="library" scope="PROVIDED" name="racc (v1.6.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, Remote: ruby-2.5.9-p229) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
35
- <orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, Remote: ruby-2.5.9-p229) [gem]" level="application" />
36
- <orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.2, Remote: ruby-2.5.9-p229) [gem]" level="application" />
37
- <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, Remote: ruby-2.5.9-p229) [gem]" level="application" />
38
- <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, Remote: ruby-2.5.9-p229) [gem]" level="application" />
39
- <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, Remote: ruby-2.5.9-p229) [gem]" level="application" />
40
- <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
41
- <orderEntry type="library" scope="PROVIDED" name="thor (v1.2.1, Remote: ruby-2.5.9-p229) [gem]" level="application" />
42
- <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, Remote: ruby-2.5.9-p229) [gem]" level="application" />
43
- <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, Remote: ruby-2.5.9-p229) [gem]" level="application" />
44
- <orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.7.5, Remote: ruby-2.5.9-p229) [gem]" level="application" />
45
- <orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, Remote: ruby-2.5.9-p229) [gem]" level="application" />
46
- <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.4, Remote: ruby-2.5.9-p229) [gem]" level="application" />
15
+ <orderEntry type="library" scope="PROVIDED" name="actioncable (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
16
+ <orderEntry type="library" scope="PROVIDED" name="actionmailbox (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
17
+ <orderEntry type="library" scope="PROVIDED" name="actionmailer (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
18
+ <orderEntry type="library" scope="PROVIDED" name="actionpack (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
19
+ <orderEntry type="library" scope="PROVIDED" name="actiontext (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
20
+ <orderEntry type="library" scope="PROVIDED" name="actionview (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
21
+ <orderEntry type="library" scope="PROVIDED" name="activejob (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
22
+ <orderEntry type="library" scope="PROVIDED" name="activemodel (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
23
+ <orderEntry type="library" scope="PROVIDED" name="activerecord (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
24
+ <orderEntry type="library" scope="PROVIDED" name="activestorage (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
25
+ <orderEntry type="library" scope="PROVIDED" name="activesupport (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
26
+ <orderEntry type="library" scope="PROVIDED" name="addressable (v2.8.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
27
+ <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, Remote: ruby-3.1.1-p18) [gem]" level="application" />
28
+ <orderEntry type="library" scope="PROVIDED" name="builder (v3.2.4, Remote: ruby-3.1.1-p18) [gem]" level="application" />
29
+ <orderEntry type="library" scope="PROVIDED" name="byebug (v11.1.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
30
+ <orderEntry type="library" scope="PROVIDED" name="capybara (v3.36.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
31
+ <orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.10, Remote: ruby-3.1.1-p18) [gem]" level="application" />
32
+ <orderEntry type="library" scope="PROVIDED" name="crass (v1.0.6, Remote: ruby-3.1.1-p18) [gem]" level="application" />
33
+ <orderEntry type="library" scope="PROVIDED" name="database_cleaner-active_record (v2.0.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
34
+ <orderEntry type="library" scope="PROVIDED" name="database_cleaner-core (v2.0.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
35
+ <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
36
+ <orderEntry type="library" scope="PROVIDED" name="digest (v3.1.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
37
+ <orderEntry type="library" scope="PROVIDED" name="erubi (v1.10.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
38
+ <orderEntry type="library" scope="PROVIDED" name="factory_bot_rails (v6.2.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
39
+ <orderEntry type="library" scope="PROVIDED" name="globalid (v1.0.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
40
+ <orderEntry type="library" scope="PROVIDED" name="i18n (v1.10.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
41
+ <orderEntry type="library" scope="PROVIDED" name="mail (v2.7.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
42
+ <orderEntry type="library" scope="PROVIDED" name="marcel (v1.0.2, Remote: ruby-3.1.1-p18) [gem]" level="application" />
43
+ <orderEntry type="library" scope="PROVIDED" name="matrix (v0.4.2, Remote: ruby-3.1.1-p18) [gem]" level="application" />
44
+ <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
45
+ <orderEntry type="library" scope="PROVIDED" name="mini_mime (v1.1.2, Remote: ruby-3.1.1-p18) [gem]" level="application" />
46
+ <orderEntry type="library" scope="PROVIDED" name="minitest (v5.15.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
47
+ <orderEntry type="library" scope="PROVIDED" name="net-imap (v0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
48
+ <orderEntry type="library" scope="PROVIDED" name="net-pop (v0.1.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
49
+ <orderEntry type="library" scope="PROVIDED" name="net-smtp (v0.3.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
50
+ <orderEntry type="library" scope="PROVIDED" name="nio4r (v2.5.8, Remote: ruby-3.1.1-p18) [gem]" level="application" />
51
+ <orderEntry type="library" scope="PROVIDED" name="racc (v1.6.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
52
+ <orderEntry type="library" scope="PROVIDED" name="rack (v2.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
53
+ <orderEntry type="library" scope="PROVIDED" name="rack-test (v1.1.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
54
+ <orderEntry type="library" scope="PROVIDED" name="rails (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
55
+ <orderEntry type="library" scope="PROVIDED" name="rails-dom-testing (v2.0.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
56
+ <orderEntry type="library" scope="PROVIDED" name="rails-html-sanitizer (v1.4.2, Remote: ruby-3.1.1-p18) [gem]" level="application" />
57
+ <orderEntry type="library" scope="PROVIDED" name="railties (v7.0.2.3, Remote: ruby-3.1.1-p18) [gem]" level="application" />
58
+ <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
59
+ <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, Remote: ruby-3.1.1-p18) [gem]" level="application" />
60
+ <orderEntry type="library" scope="PROVIDED" name="rbs (v2.1.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
61
+ <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, Remote: ruby-3.1.1-p18) [gem]" level="application" />
62
+ <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
63
+ <orderEntry type="library" scope="PROVIDED" name="thor (v1.2.1, Remote: ruby-3.1.1-p18) [gem]" level="application" />
64
+ <orderEntry type="library" scope="PROVIDED" name="tzinfo (v2.0.4, Remote: ruby-3.1.1-p18) [gem]" level="application" />
65
+ <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.1.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
66
+ <orderEntry type="library" scope="PROVIDED" name="websocket-driver (v0.7.5, Remote: ruby-3.1.1-p18) [gem]" level="application" />
67
+ <orderEntry type="library" scope="PROVIDED" name="websocket-extensions (v0.1.5, Remote: ruby-3.1.1-p18) [gem]" level="application" />
68
+ <orderEntry type="library" scope="PROVIDED" name="xpath (v3.2.0, Remote: ruby-3.1.1-p18) [gem]" level="application" />
69
+ <orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.5.4, Remote: ruby-3.1.1-p18) [gem]" level="application" />
47
70
  </component>
48
71
  <component name="RakeTasksCache">
49
72
  <option name="myRootTask">
data/README.md CHANGED
@@ -105,8 +105,10 @@ end
105
105
  - Capture event when file upload has failed: `<attr_name>_error_upload`
106
106
  ```ruby
107
107
  class User < ApplicationRecord
108
- def photo_error_upload(error)
109
- puts "Failed with #{error}"
108
+ # @param error [StandardError]
109
+ # @param file_data [Hash<'filename'>]
110
+ def photo_error_upload(error, file_data)
111
+ puts "Failed uploading photo #{file_data['filename']}: #{error.message}"
110
112
  end
111
113
  end
112
114
  ```
@@ -114,8 +116,13 @@ end
114
116
  - Capture event when file has been uploaded: `<attr_name>_after_upload`
115
117
  ```ruby
116
118
  class User < ApplicationRecord
117
- def photo_after_upload
118
- puts "Photo has been uploaded"
119
+ # @param file_data [Hash<'filename'>]
120
+ def photo_after_upload(file_data)
121
+ puts "Photo #{file_data['filename']} has been uploaded"
122
+ end
123
+
124
+ def photo_after_upload_all
125
+ puts "All photos have been uploaded"
119
126
  end
120
127
  end
121
128
  ```
@@ -40,11 +40,16 @@ module ActivestorageDelayed
40
40
  "#{send(:id)}-#{name}#{File.extname(filename)}"
41
41
  end
42
42
 
43
- define_method "#{attr_name}_after_upload" do
43
+ # @param _file_data [Hash<'filename'>]
44
+ define_method "#{attr_name}_after_upload" do |_file_data|
45
+ end
46
+
47
+ define_method "#{attr_name}_after_upload_all" do
44
48
  end
45
49
 
46
50
  # @param _error (Exception)
47
- define_method "#{attr_name}_error_upload" do |_error|
51
+ # @param _file_data [Hash<'filename'>]
52
+ define_method "#{attr_name}_error_upload" do |_error, _file_data|
48
53
  end
49
54
  end
50
55
  end
@@ -13,30 +13,31 @@ module ActivestorageDelayed
13
13
  return unless delayed_upload
14
14
 
15
15
  remove_files
16
- save_changes if upload_photos
16
+ upload_photos
17
+ save_changes
17
18
  end
18
19
 
19
20
  private
20
21
 
21
22
  def upload_photos
22
23
  tmp_files_data.each(&method(:upload_photo))
23
- model.send("#{attr_name}_after_upload")
24
- true
25
- rescue => e # rubocop:disable Style/RescueStandardError
26
- print_failure(e)
27
- false
24
+ model.send("#{attr_name}_after_upload_all")
28
25
  end
29
26
 
30
27
  def upload_photo(file_data)
31
28
  parse_file_io(file_data) do |io|
32
29
  file_data['io'] = io
33
30
  model.send(attr_name).attach(file_data.transform_keys(&:to_sym))
31
+ model.send("#{attr_name}_after_upload", file_data)
32
+ rescue => e # rubocop:disable Style/RescueStandardError
33
+ print_failure(e, file_data)
34
34
  end
35
35
  end
36
36
 
37
- def print_failure(error)
38
- Rails.logger.error("***#{self.class.name} -> Failed uploading files: #{error.message}. #{error.backtrace[0..20]}")
39
- model.send("#{attr_name}_error_upload", error)
37
+ def print_failure(error, file_data = {})
38
+ details = "#{error.message}. #{error.backtrace[0..20]}"
39
+ Rails.logger.error("***#{self.class.name} -> Failed uploading file (#{file_data['filename']}): #{details}")
40
+ model.send("#{attr_name}_error_upload", error, file_data)
40
41
  end
41
42
 
42
43
  def save_changes
@@ -44,7 +45,7 @@ module ActivestorageDelayed
44
45
  delayed_upload.destroy!
45
46
  end
46
47
 
47
- # @return [Array<Hash<io: StringIO, filename: String, content_type: String>]
48
+ # @return [Array<Hash<io: StringIO, filename: String, content_type: String>>]
48
49
  def tmp_files_data
49
50
  @tmp_files_data ||= begin
50
51
  files = JSON.parse(delayed_upload.files || '[]')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActivestorageDelayed
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
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.2.0
4
+ version: 0.3.0
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-05-06 00:00:00.000000000 Z
11
+ date: 2022-07-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activestorage