active_storage-send_zip 0.3.5 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4a1c89a7b8a630d378b77f1e0cadd4ddb7eaadaa96f4040875ed4cc41944775
4
- data.tar.gz: b366d585f90a600c4210053c52a1c69e13d7cd226574ad3f6b3400c6d37729f0
3
+ metadata.gz: 3cb438270e8304e1c4feea19d3c14c254cdf819978eeb82cb58a74b9bbcdf05e
4
+ data.tar.gz: e8ca7ec1429aa7b3d770c7ca671150ea039da739095ccea4994d161a6e583130
5
5
  SHA512:
6
- metadata.gz: b9f936395e0bbb982b150b79a513d91f8703238ec3b70d7f95a0c7c00d417696dc45a32366294e42f2b26de6c5bc67628dd67ac7e42fd9cb0d96b1382459144a
7
- data.tar.gz: 4a9087b99c8bb4116af9b2ea553a58091827a4c4fbc1a305f378e573f89d64b2d0180a1d7eed664ea193f19cd0ec41c3ffb610878e9d9b2a017a96a5658372c7
6
+ metadata.gz: b14c230be0bf9b23b26b94b3d5efc3cdac7917eb1538bbdfb85ff024d2bde09ee7213e42a82f594dff16daecfa2a75dae479f6ecbacd213b9f476a03121e6602
7
+ data.tar.gz: b8966756b2582528fc4e4c5378e8944b9b276c706160f23dcaa8e9912eb6ba9d70e1f07dc2270ba97dd3ca8ccbe4e1355fd400b88910c7a9414e534540733256
@@ -0,0 +1,24 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+
9
+ jobs:
10
+ test:
11
+ runs-on: ubuntu-latest
12
+
13
+ steps:
14
+ - uses: actions/checkout@v3
15
+
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1
18
+ with:
19
+ ruby-version: 3.2.7
20
+ bundler-cache: true
21
+
22
+ - name: Run tests
23
+ run: bundle exec rake test
24
+
data/AGENTS.md ADDED
@@ -0,0 +1,56 @@
1
+ # AGENTS.md
2
+
3
+ ## Build/Lint/Test Commands
4
+
5
+ ### Setup
6
+ ```bash
7
+ bin/setup # Install dependencies
8
+ ```
9
+
10
+ ### Testing
11
+ ```bash
12
+ rake test # Run all tests
13
+ ```
14
+
15
+ ### Development
16
+ ```bash
17
+ bin/console # Interactive Ruby console
18
+ bundle exec rake install # Install gem locally
19
+ ```
20
+
21
+ ## Code Style Guidelines
22
+
23
+ ### Imports
24
+ - Group standard library requires first, then third-party, then local files
25
+ - Use double quotes for require paths
26
+ - Place all requires at the top of the file
27
+
28
+ ### Formatting
29
+ - Use 2 space indentation (no tabs)
30
+ - Max line length 80-100 characters
31
+ - Add empty line at end of file
32
+ - Use frozen_string_literal: true magic comment
33
+ - Add newline after class/module definition
34
+
35
+ ### Naming Conventions
36
+ - Use snake_case for methods and variables
37
+ - Use PascalCase for classes and modules
38
+ - Use SCREAMING_SNAKE_CASE for constants
39
+ - Method names should be descriptive verbs
40
+
41
+ ### Types
42
+ - Use explicit return types in comments for public methods
43
+ - Document parameter types with YARD-style comments
44
+ - Use appropriate Ruby types (String, Array, Hash, etc.)
45
+
46
+ ### Error Handling
47
+ - Raise specific exception types (ArgumentError, StandardError, etc.)
48
+ - Use guard clauses for early returns
49
+ - Handle edge cases explicitly
50
+ - Provide meaningful error messages
51
+
52
+ ### Documentation
53
+ - Add YARD-style comments for all public methods
54
+ - Include @param and @return tags
55
+ - Document complex logic with inline comments
56
+ - Keep comments up-to-date with code changes
data/CHANGELOG.yml CHANGED
@@ -1,3 +1,6 @@
1
+ 0.4.1:
2
+ - fix issue with `has_many_attached` associations not working properly with folder names
3
+ - properly handle `ActiveStorage::Attached::Many` objects by iterating through their attachments
1
4
  0.3.4:
2
5
  - add resize before download capability
3
6
  0.3.2:
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage-send_zip (0.3.5)
4
+ active_storage-send_zip (0.5.0)
5
5
  rails (> 5.2)
6
- rubyzip (< 3.0)
6
+ rubyzip (>= 2.1.0, < 4.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -59,13 +59,13 @@ class HolidaysController < ApplicationController
59
59
  include ActiveStorage::SendZip
60
60
 
61
61
  def zip
62
- send_zip {
62
+ send_zip({
63
63
  'Holidays in Lyon <3' => Holidays.where(place: 'lyon').first.pictures,
64
64
  'Holidays in Paris' => [
65
65
  'Eiffle Tower' => Holidays.where(place: 'eiffle_tower').first.pictures,
66
66
  Holidays.where(place: 'paris').first.pictures
67
67
  ]
68
- }
68
+ })
69
69
  end
70
70
  end
71
71
  ~~~
@@ -87,6 +87,8 @@ Will produce a `.zip` archive like this:
87
87
  └── c.gif
88
88
  ~~~
89
89
 
90
+ > Note: `has_many_attached` associations (like `Holidays.where(place: 'lyon').first.pictures`) are now properly supported and will automatically extract the individual attachments.
91
+
90
92
 
91
93
  ### Resize images before downloading
92
94
 
@@ -41,5 +41,5 @@ Gem::Specification.new do |spec|
41
41
  spec.add_development_dependency 'minitest', '~> 5.0'
42
42
  spec.add_development_dependency 'rake'
43
43
  spec.add_dependency 'rails', '> 5.2'
44
- spec.add_dependency 'rubyzip', '< 3.0'
44
+ spec.add_dependency 'rubyzip', ['>= 2.1.0', '< 4.0']
45
45
  end
@@ -3,6 +3,6 @@
3
3
  module ActiveStorage
4
4
  module SendZip
5
5
  # The version of this gem
6
- VERSION = '0.3.5'
6
+ VERSION = '0.5.0'
7
7
  end
8
8
  end
@@ -20,9 +20,16 @@ module ActiveStorage
20
20
  temp_folder = Dir.mktmpdir 'active_storage-send_zip'
21
21
 
22
22
  if files.is_a? Hash
23
- filepaths = construct_with_hash(files, temp_folder)
23
+ construct_with_hash(files, temp_folder)
24
24
  elsif files.respond_to? :each
25
- files.each { |file| save_file_on_server(file, temp_folder, resize_to_limit: resize_to_limit) }
25
+ # Handle ActiveStorage::Attached::Many objects by iterating through their attachments
26
+ if defined?(ActiveStorage::Attached::Many) && files.is_a?(ActiveStorage::Attached::Many)
27
+ files.attachments.each do |attachment|
28
+ save_file_on_server(attachment, temp_folder, resize_to_limit: resize_to_limit)
29
+ end
30
+ else
31
+ files.each { |file| save_file_on_server(file, temp_folder, resize_to_limit: resize_to_limit) }
32
+ end
26
33
  else
27
34
  raise ArgumentError, '`files` must be an hash or an iterable object'
28
35
  end
@@ -38,6 +45,11 @@ module ActiveStorage
38
45
  filepaths = []
39
46
 
40
47
  files.each do |subfolder, filesHash|
48
+ # Handle ActiveStorage::Attached::Many objects by converting them to attachments array
49
+ if defined?(ActiveStorage::Attached::Many) && filesHash.is_a?(ActiveStorage::Attached::Many)
50
+ filesHash = filesHash.attachments
51
+ end
52
+
41
53
  filesHash = [filesHash] unless filesHash.is_a? Array
42
54
 
43
55
  filesHash.each do |f|
@@ -84,9 +96,7 @@ module ActiveStorage
84
96
  end
85
97
 
86
98
  # resize images if needed
87
- unless resize_to_limit.nil?
88
- file = file.variant(resize_to_limit: resize_to_limit).processed
89
- end
99
+ file = file.variant(resize_to_limit: resize_to_limit).processed unless resize_to_limit.nil?
90
100
 
91
101
  # write the file on disk
92
102
  File.open(filepath, 'wb') { |f| f.write(file.service.download(file.key)) }
@@ -109,7 +119,7 @@ module ActiveStorage
109
119
  Zip::OutputStream.open(temp_file) { |zos| }
110
120
 
111
121
  # open the zip
112
- Zip::File.open(temp_file.path, Zip::File::CREATE) do |zip|
122
+ Zip::File.open(temp_file.path, create: true) do |zip|
113
123
  files.each do |filepath|
114
124
  filepath_zip = filepath.sub(folderpath, '').sub(File::SEPARATOR, '')
115
125
  zip.add filepath_zip, filepath
@@ -117,7 +127,7 @@ module ActiveStorage
117
127
  end
118
128
 
119
129
  File.read(temp_file.path)
120
- ensure
130
+
121
131
  # close all ressources & remove temporary files
122
132
  # temp_file.close
123
133
  # temp_file.unlink
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: active_storage-send_zip
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Rousseau
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2024-02-27 00:00:00.000000000 Z
12
+ date: 2025-10-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -71,16 +71,22 @@ dependencies:
71
71
  name: rubyzip
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: 2.1.0
74
77
  - - "<"
75
78
  - !ruby/object:Gem::Version
76
- version: '3.0'
79
+ version: '4.0'
77
80
  type: :runtime
78
81
  prerelease: false
79
82
  version_requirements: !ruby/object:Gem::Requirement
80
83
  requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.1.0
81
87
  - - "<"
82
88
  - !ruby/object:Gem::Version
83
- version: '3.0'
89
+ version: '4.0'
84
90
  description: Add a `send_zip` method in your Rails controller to send a `.zip` file
85
91
  containing one (or many) ActiveStorage object(s)
86
92
  email:
@@ -89,8 +95,10 @@ executables: []
89
95
  extensions: []
90
96
  extra_rdoc_files: []
91
97
  files:
98
+ - ".github/workflows/ci.yml"
92
99
  - ".gitignore"
93
100
  - ".travis.yml"
101
+ - AGENTS.md
94
102
  - CHANGELOG.yml
95
103
  - CODE_OF_CONDUCT.md
96
104
  - Gemfile
@@ -126,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
134
  - !ruby/object:Gem::Version
127
135
  version: '0'
128
136
  requirements: []
129
- rubygems_version: 3.4.20
137
+ rubygems_version: 3.4.19
130
138
  signing_key:
131
139
  specification_version: 4
132
140
  summary: Create a zip from one or more Active Storage objects