File tree Expand file tree Collapse file tree 6 files changed +19
-9
lines changed Expand file tree Collapse file tree 6 files changed +19
-9
lines changed Original file line number Diff line number Diff line change
1
+ 0,3,1 :
2
+ - correct comportement when `ActiveStorage::Attached::Many` is given as paramter
1
3
0.3.0 :
2
4
- correct subfolders creation (and break some methods signature)
3
5
0.2.0 :
Original file line number Diff line number Diff line change @@ -5,6 +5,6 @@ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
5
5
# Specify your gem's dependencies in active_storage-send_zip.gemspec
6
6
gemspec
7
7
8
- gem "rails" , "~ > 5.2"
8
+ gem "rails" , "> 5.2"
9
9
10
10
gem "rubyzip" , "~> 1.2"
Original file line number Diff line number Diff line change 1
1
PATH
2
2
remote: .
3
3
specs:
4
- active_storage-send_zip (0.2.0 )
4
+ active_storage-send_zip (0.3.1 )
5
5
6
6
GEM
7
7
remote: https://rubygems.org/
@@ -122,9 +122,9 @@ DEPENDENCIES
122
122
active_storage-send_zip !
123
123
bundler (~> 1.17 )
124
124
minitest (~> 5.0 )
125
- rails (~ > 5.2 )
125
+ rails (> 5.2 )
126
126
rake (~> 10.0 )
127
127
rubyzip (~> 1.2 )
128
128
129
129
BUNDLED WITH
130
- 1.17.1
130
+ 1.17.2
Original file line number Diff line number Diff line change 1
1
module ActiveStorage
2
2
module SendZip
3
3
# The version of this gem
4
- VERSION = '0.3.0 ' . freeze
4
+ VERSION = '0.3.1 ' . freeze
5
5
end
6
6
end
Original file line number Diff line number Diff line change @@ -9,16 +9,14 @@ module ActiveStorage
9
9
module SendZipHelper
10
10
# Download active storage files on server in a temporary folder
11
11
#
12
- # @param files [ActiveStorage::Attached::Many] files to save
12
+ # @param files [ActiveStorage::Attached::One|ActiveStorage::Attached:: Many|Array|Hash] file(s) to save
13
13
# @return [String] folder path of saved files
14
14
def self . save_files_on_server ( files )
15
15
require 'zip'
16
16
# get a temporary folder and create it
17
17
temp_folder = Dir . mktmpdir 'active_storage-send_zip'
18
18
19
- if files . is_a? Array
20
- files . each { |file | save_file_on_server ( file , temp_folder ) }
21
- elsif files . is_a? Hash
19
+ if files . is_a? Hash
22
20
filepaths = [ ]
23
21
24
22
files . each do |subfolder , filesHash |
@@ -27,6 +25,10 @@ def self.save_files_on_server(files)
27
25
filepaths << save_file_on_server ( f , temp_folder , subfolder : subfolder . to_s )
28
26
end
29
27
end
28
+ elsif files . respond_to? :each
29
+ files . each { |file | save_file_on_server ( file , temp_folder ) }
30
+ else
31
+ raise ArgumentError , '`files` must be an hash or an iterable object'
30
32
end
31
33
32
34
temp_folder
Original file line number Diff line number Diff line change @@ -54,6 +54,12 @@ def test_it_should_save_files_in_differents_folders
54
54
assert_produce_nested_files files , folder_count : 2 , files_count : 3
55
55
end
56
56
57
+ def test_it_should_raise_an_exception
58
+ assert_raises ArgumentError do
59
+ ActiveStorage ::SendZipHelper . save_files_on_server 'bad boi'
60
+ end
61
+ end
62
+
57
63
def test_it_should_save_files_in_differents_folders_with_root_files
58
64
files = {
59
65
'folder A' => [
You can’t perform that action at this time.
0 commit comments