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 +4 -4
- data/Gemfile.lock +80 -64
- data/README.md +8 -1
- data/active_storage-send_zip.gemspec +4 -2
- data/lib/active_storage/send_zip/version.rb +3 -1
- data/lib/active_storage/send_zip_helper.rb +32 -9
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc98380d75e0dea755962244b39c4f71eef7ab10e287bde9a8eb9069e72938b5
|
4
|
+
data.tar.gz: 991f72af92ec9d212bfe0ce70c1ac05657de73ce569863f42a9522c70a8028a3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 485893e2b20b30be9586e6b33852baf7b25ba01a788e722c65e46290484055823c7f0abb04b88e1cabac9f82ec10722345c2af604c67ca66a573e0c24fa1818e
|
7
|
+
data.tar.gz: 2e34ff1b3a2fa5eef2137479b23fcbf3968a9702435f4cee6b8d2d09a881ef86459df9601194aeeb02dd922049dd91550976db0a58fe6921e5a94b6de52a999a
|
data/Gemfile.lock
CHANGED
@@ -1,64 +1,77 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
active_storage-send_zip (0.3.
|
4
|
+
active_storage-send_zip (0.3.3)
|
5
5
|
rails (> 5.2)
|
6
|
-
rubyzip (
|
6
|
+
rubyzip (< 3.0)
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
actioncable (
|
12
|
-
actionpack (=
|
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
|
-
|
16
|
-
actionpack (=
|
17
|
-
|
18
|
-
|
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 (
|
22
|
-
actionview (=
|
23
|
-
activesupport (=
|
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
|
28
|
-
|
29
|
-
|
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.
|
34
|
-
activejob (
|
35
|
-
activesupport (=
|
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 (
|
38
|
-
activesupport (=
|
39
|
-
activerecord (
|
40
|
-
activemodel (=
|
41
|
-
activesupport (=
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
activerecord (=
|
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 (
|
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
|
-
|
53
|
-
builder (3.2.
|
54
|
-
concurrent-ruby (1.1.
|
55
|
-
crass (1.0.
|
56
|
-
erubi (1.
|
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.
|
72
|
+
i18n (1.8.2)
|
60
73
|
concurrent-ruby (~> 1.0)
|
61
|
-
loofah (2.
|
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.
|
70
|
-
mini_mime (1.0.
|
82
|
+
mimemagic (0.3.4)
|
83
|
+
mini_mime (1.0.2)
|
71
84
|
mini_portile2 (2.4.0)
|
72
|
-
minitest (5.
|
73
|
-
nio4r (2.
|
74
|
-
nokogiri (1.10.
|
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.
|
89
|
+
rack (2.2.2)
|
77
90
|
rack-test (1.1.0)
|
78
91
|
rack (>= 1.0, < 3)
|
79
|
-
rails (
|
80
|
-
actioncable (=
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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 (=
|
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
|
96
|
-
loofah (~> 2.
|
97
|
-
railties (
|
98
|
-
actionpack (=
|
99
|
-
activesupport (=
|
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.
|
117
|
+
thor (>= 0.20.3, < 2.0)
|
103
118
|
rake (10.5.0)
|
104
|
-
rubyzip (
|
105
|
-
sprockets (
|
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.
|
127
|
+
thor (1.0.1)
|
113
128
|
thread_safe (0.3.6)
|
114
|
-
tzinfo (1.2.
|
129
|
+
tzinfo (1.2.6)
|
115
130
|
thread_safe (~> 0.1)
|
116
|
-
websocket-driver (0.7.
|
131
|
+
websocket-driver (0.7.1)
|
117
132
|
websocket-extensions (>= 0.1.0)
|
118
|
-
websocket-extensions (0.1.
|
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' =>
|
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
|
42
|
-
spec.add_dependency
|
43
|
+
spec.add_dependency 'rails', '> 5.2'
|
44
|
+
spec.add_dependency 'rubyzip', '< 3.0'
|
43
45
|
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
|
-
|
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.
|
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:
|
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: '
|
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: '
|
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
|
-
|
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
|