active_storage-send_zip 0.3.2 → 0.3.3

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: a759d725f127cfcc104cb260006573890883f6ab47b8791090b438d0d71508b9
4
- data.tar.gz: 3199a753f48fdc3b4ff8664fae7572dd51676d01dba59803be2d623671491821
3
+ metadata.gz: dc98380d75e0dea755962244b39c4f71eef7ab10e287bde9a8eb9069e72938b5
4
+ data.tar.gz: 991f72af92ec9d212bfe0ce70c1ac05657de73ce569863f42a9522c70a8028a3
5
5
  SHA512:
6
- metadata.gz: e832a1d02d78d6cab4014b5ab2bf4c736dc5c9f77c91fefbc1cd0db1c4d678d494fb261acad9fce16e8d9af59b339fd2988805c8a8f6110f92323e018e755e93
7
- data.tar.gz: 61484fd7cda8f6599658a6aaaafff6e64a349ee57c9fa3a21863e3043557e1b22582050a2cf2436e05cb257ff93d8b3168a043e52dddd553eeeb92a05600f5da
6
+ metadata.gz: 485893e2b20b30be9586e6b33852baf7b25ba01a788e722c65e46290484055823c7f0abb04b88e1cabac9f82ec10722345c2af604c67ca66a573e0c24fa1818e
7
+ data.tar.gz: 2e34ff1b3a2fa5eef2137479b23fcbf3968a9702435f4cee6b8d2d09a881ef86459df9601194aeeb02dd922049dd91550976db0a58fe6921e5a94b6de52a999a
@@ -1,64 +1,77 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage-send_zip (0.3.2)
4
+ active_storage-send_zip (0.3.3)
5
5
  rails (> 5.2)
6
- rubyzip (~> 1.2)
6
+ rubyzip (< 3.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- actioncable (5.2.2)
12
- actionpack (= 5.2.2)
11
+ actioncable (6.0.2.1)
12
+ actionpack (= 6.0.2.1)
13
13
  nio4r (~> 2.0)
14
14
  websocket-driver (>= 0.6.1)
15
- actionmailer (5.2.2)
16
- actionpack (= 5.2.2)
17
- actionview (= 5.2.2)
18
- activejob (= 5.2.2)
15
+ actionmailbox (6.0.2.1)
16
+ actionpack (= 6.0.2.1)
17
+ activejob (= 6.0.2.1)
18
+ activerecord (= 6.0.2.1)
19
+ activestorage (= 6.0.2.1)
20
+ activesupport (= 6.0.2.1)
21
+ mail (>= 2.7.1)
22
+ actionmailer (6.0.2.1)
23
+ actionpack (= 6.0.2.1)
24
+ actionview (= 6.0.2.1)
25
+ activejob (= 6.0.2.1)
19
26
  mail (~> 2.5, >= 2.5.4)
20
27
  rails-dom-testing (~> 2.0)
21
- actionpack (5.2.2)
22
- actionview (= 5.2.2)
23
- activesupport (= 5.2.2)
24
- rack (~> 2.0)
28
+ actionpack (6.0.2.1)
29
+ actionview (= 6.0.2.1)
30
+ activesupport (= 6.0.2.1)
31
+ rack (~> 2.0, >= 2.0.8)
25
32
  rack-test (>= 0.6.3)
26
33
  rails-dom-testing (~> 2.0)
27
- rails-html-sanitizer (~> 1.0, >= 1.0.2)
28
- actionview (5.2.2)
29
- activesupport (= 5.2.2)
34
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
35
+ actiontext (6.0.2.1)
36
+ actionpack (= 6.0.2.1)
37
+ activerecord (= 6.0.2.1)
38
+ activestorage (= 6.0.2.1)
39
+ activesupport (= 6.0.2.1)
40
+ nokogiri (>= 1.8.5)
41
+ actionview (6.0.2.1)
42
+ activesupport (= 6.0.2.1)
30
43
  builder (~> 3.1)
31
44
  erubi (~> 1.4)
32
45
  rails-dom-testing (~> 2.0)
33
- rails-html-sanitizer (~> 1.0, >= 1.0.3)
34
- activejob (5.2.2)
35
- activesupport (= 5.2.2)
46
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
47
+ activejob (6.0.2.1)
48
+ activesupport (= 6.0.2.1)
36
49
  globalid (>= 0.3.6)
37
- activemodel (5.2.2)
38
- activesupport (= 5.2.2)
39
- activerecord (5.2.2)
40
- activemodel (= 5.2.2)
41
- activesupport (= 5.2.2)
42
- arel (>= 9.0)
43
- activestorage (5.2.2)
44
- actionpack (= 5.2.2)
45
- activerecord (= 5.2.2)
50
+ activemodel (6.0.2.1)
51
+ activesupport (= 6.0.2.1)
52
+ activerecord (6.0.2.1)
53
+ activemodel (= 6.0.2.1)
54
+ activesupport (= 6.0.2.1)
55
+ activestorage (6.0.2.1)
56
+ actionpack (= 6.0.2.1)
57
+ activejob (= 6.0.2.1)
58
+ activerecord (= 6.0.2.1)
46
59
  marcel (~> 0.3.1)
47
- activesupport (5.2.2)
60
+ activesupport (6.0.2.1)
48
61
  concurrent-ruby (~> 1.0, >= 1.0.2)
49
62
  i18n (>= 0.7, < 2)
50
63
  minitest (~> 5.1)
51
64
  tzinfo (~> 1.1)
52
- arel (9.0.0)
53
- builder (3.2.3)
54
- concurrent-ruby (1.1.4)
55
- crass (1.0.4)
56
- erubi (1.8.0)
65
+ zeitwerk (~> 2.2)
66
+ builder (3.2.4)
67
+ concurrent-ruby (1.1.6)
68
+ crass (1.0.6)
69
+ erubi (1.9.0)
57
70
  globalid (0.4.2)
58
71
  activesupport (>= 4.2.0)
59
- i18n (1.5.3)
72
+ i18n (1.8.2)
60
73
  concurrent-ruby (~> 1.0)
61
- loofah (2.2.3)
74
+ loofah (2.4.0)
62
75
  crass (~> 1.0.2)
63
76
  nokogiri (>= 1.5.9)
64
77
  mail (2.7.1)
@@ -66,56 +79,59 @@ GEM
66
79
  marcel (0.3.3)
67
80
  mimemagic (~> 0.3.2)
68
81
  method_source (0.9.2)
69
- mimemagic (0.3.3)
70
- mini_mime (1.0.1)
82
+ mimemagic (0.3.4)
83
+ mini_mime (1.0.2)
71
84
  mini_portile2 (2.4.0)
72
- minitest (5.11.3)
73
- nio4r (2.3.1)
74
- nokogiri (1.10.1)
85
+ minitest (5.14.0)
86
+ nio4r (2.5.2)
87
+ nokogiri (1.10.8)
75
88
  mini_portile2 (~> 2.4.0)
76
- rack (2.0.6)
89
+ rack (2.2.2)
77
90
  rack-test (1.1.0)
78
91
  rack (>= 1.0, < 3)
79
- rails (5.2.2)
80
- actioncable (= 5.2.2)
81
- actionmailer (= 5.2.2)
82
- actionpack (= 5.2.2)
83
- actionview (= 5.2.2)
84
- activejob (= 5.2.2)
85
- activemodel (= 5.2.2)
86
- activerecord (= 5.2.2)
87
- activestorage (= 5.2.2)
88
- activesupport (= 5.2.2)
92
+ rails (6.0.2.1)
93
+ actioncable (= 6.0.2.1)
94
+ actionmailbox (= 6.0.2.1)
95
+ actionmailer (= 6.0.2.1)
96
+ actionpack (= 6.0.2.1)
97
+ actiontext (= 6.0.2.1)
98
+ actionview (= 6.0.2.1)
99
+ activejob (= 6.0.2.1)
100
+ activemodel (= 6.0.2.1)
101
+ activerecord (= 6.0.2.1)
102
+ activestorage (= 6.0.2.1)
103
+ activesupport (= 6.0.2.1)
89
104
  bundler (>= 1.3.0)
90
- railties (= 5.2.2)
105
+ railties (= 6.0.2.1)
91
106
  sprockets-rails (>= 2.0.0)
92
107
  rails-dom-testing (2.0.3)
93
108
  activesupport (>= 4.2.0)
94
109
  nokogiri (>= 1.6)
95
- rails-html-sanitizer (1.0.4)
96
- loofah (~> 2.2, >= 2.2.2)
97
- railties (5.2.2)
98
- actionpack (= 5.2.2)
99
- activesupport (= 5.2.2)
110
+ rails-html-sanitizer (1.3.0)
111
+ loofah (~> 2.3)
112
+ railties (6.0.2.1)
113
+ actionpack (= 6.0.2.1)
114
+ activesupport (= 6.0.2.1)
100
115
  method_source
101
116
  rake (>= 0.8.7)
102
- thor (>= 0.19.0, < 2.0)
117
+ thor (>= 0.20.3, < 2.0)
103
118
  rake (10.5.0)
104
- rubyzip (1.2.2)
105
- sprockets (3.7.2)
119
+ rubyzip (2.2.0)
120
+ sprockets (4.0.0)
106
121
  concurrent-ruby (~> 1.0)
107
122
  rack (> 1, < 3)
108
123
  sprockets-rails (3.2.1)
109
124
  actionpack (>= 4.0)
110
125
  activesupport (>= 4.0)
111
126
  sprockets (>= 3.0.0)
112
- thor (0.20.3)
127
+ thor (1.0.1)
113
128
  thread_safe (0.3.6)
114
- tzinfo (1.2.5)
129
+ tzinfo (1.2.6)
115
130
  thread_safe (~> 0.1)
116
- websocket-driver (0.7.0)
131
+ websocket-driver (0.7.1)
117
132
  websocket-extensions (>= 0.1.0)
118
- websocket-extensions (0.1.3)
133
+ websocket-extensions (0.1.4)
134
+ zeitwerk (2.2.2)
119
135
 
120
136
  PLATFORMS
121
137
  ruby
data/README.md CHANGED
@@ -61,7 +61,10 @@ class HolidaysController < ApplicationController
61
61
  def zip
62
62
  send_zip {
63
63
  'Holidays in Lyon <3' => Holidays.where(place: 'lyon').first.pictures,
64
- 'Holidays in Paris' => Holidays.where(place: 'paris').first.pictures,
64
+ 'Holidays in Paris' => [
65
+ 'Eiffle Tower' => Holidays.where(place: 'eiffle_tower').first.pictures,
66
+ Holidays.where(place: 'paris').first.pictures
67
+ ]
65
68
  }
66
69
  end
67
70
  end
@@ -75,6 +78,10 @@ Will produce a `.zip` archive like this:
75
78
  │   ├── b.png
76
79
  │   └── c.gif
77
80
  └── Holidays in Paris
81
+ ├── Eiffle Tower
82
+ ├── d.jpg
83
+ ├── e.jpg
84
+ ├── f.jpg
78
85
  ├── a.jpg
79
86
  ├── b.png
80
87
  └── c.gif
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path('lib', __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require 'active_storage/send_zip/version'
@@ -38,6 +40,6 @@ Gem::Specification.new do |spec|
38
40
  spec.add_development_dependency 'bundler', '~> 1.17'
39
41
  spec.add_development_dependency 'minitest', '~> 5.0'
40
42
  spec.add_development_dependency 'rake', '~> 10.0'
41
- spec.add_dependency "rails", "> 5.2"
42
- spec.add_dependency "rubyzip", "~> 1.2"
43
+ spec.add_dependency 'rails', '> 5.2'
44
+ spec.add_dependency 'rubyzip', '< 3.0'
43
45
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ActiveStorage
2
4
  module SendZip
3
5
  # The version of this gem
4
- VERSION = '0.3.2'.freeze
6
+ VERSION = '0.3.3'
5
7
  end
6
8
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rails'
2
4
  require 'zip'
3
5
  require 'tempfile'
@@ -17,14 +19,7 @@ module ActiveStorage
17
19
  temp_folder = Dir.mktmpdir 'active_storage-send_zip'
18
20
 
19
21
  if files.is_a? Hash
20
- filepaths = []
21
-
22
- files.each do |subfolder, filesHash|
23
- filesHash = [filesHash] unless filesHash.is_a? Array
24
- filesHash.each do |f|
25
- filepaths << save_file_on_server(f, temp_folder, subfolder: subfolder.to_s)
26
- end
27
- end
22
+ filepaths = construct_with_hash(files, temp_folder)
28
23
  elsif files.respond_to? :each
29
24
  files.each { |file| save_file_on_server(file, temp_folder) }
30
25
  else
@@ -34,6 +29,34 @@ module ActiveStorage
34
29
  temp_folder
35
30
  end
36
31
 
32
+ # Parses hash to build out directories where folders are key names
33
+ #
34
+ # @param files [ActiveStorage::Attached::One|ActiveStorage::Attached::Many|Array|Hash] file(s) to save
35
+ # @return [String] folder path of saved files
36
+ def self.construct_with_hash(files, temp_folder)
37
+ filepaths = []
38
+
39
+ files.each do |subfolder, filesHash|
40
+ filesHash = [filesHash] unless filesHash.is_a? Array
41
+
42
+ filesHash.each do |f|
43
+ # Build directory strucutre recursively for hashes
44
+ if f.is_a? Hash
45
+ # Build folder for hash entry
46
+ folder = File.join(temp_folder, subfolder.to_s)
47
+ Dir.mkdir(folder) unless Dir.exist?(folder)
48
+
49
+ filepaths += construct_with_hash(f, folder)
50
+ # Save attachement
51
+ else
52
+ filepaths << save_file_on_server(f, temp_folder, subfolder: subfolder.to_s)
53
+ end
54
+ end
55
+ end
56
+
57
+ filepaths
58
+ end
59
+
37
60
  # Save the given file on the server
38
61
  #
39
62
  # @param file [ActiveStorage::Attached] files to save
@@ -84,7 +107,7 @@ module ActiveStorage
84
107
  end
85
108
  end
86
109
 
87
- return File.read(temp_file.path)
110
+ File.read(temp_file.path)
88
111
  ensure
89
112
  # close all ressources & remove temporary files
90
113
  # temp_file.close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage-send_zip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Rousseau
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-28 00:00:00.000000000 Z
11
+ date: 2020-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: rubyzip
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - "~>"
73
+ - - "<"
74
74
  - !ruby/object:Gem::Version
75
- version: '1.2'
75
+ version: '3.0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - "~>"
80
+ - - "<"
81
81
  - !ruby/object:Gem::Version
82
- version: '1.2'
82
+ version: '3.0'
83
83
  description: Add a `send_zip` method in your Rails controller to send a `.zip` file
84
84
  containing one (or many) ActiveStorage object(s)
85
85
  email:
@@ -125,7 +125,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubygems_version: 3.0.1
128
+ rubyforge_project:
129
+ rubygems_version: 2.7.8
129
130
  signing_key:
130
131
  specification_version: 4
131
132
  summary: Create a zip from one or more Active Storage objects