active_storage-send_zip 0.4.0 → 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 +4 -4
- data/AGENTS.md +56 -0
- data/CHANGELOG.yml +3 -0
- data/Gemfile.lock +1 -1
- data/README.md +4 -2
- data/lib/active_storage/send_zip/version.rb +1 -1
- data/lib/active_storage/send_zip_helper.rb +16 -6
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3cb438270e8304e1c4feea19d3c14c254cdf819978eeb82cb58a74b9bbcdf05e
|
|
4
|
+
data.tar.gz: e8ca7ec1429aa7b3d770c7ca671150ea039da739095ccea4994d161a6e583130
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b14c230be0bf9b23b26b94b3d5efc3cdac7917eb1538bbdfb85ff024d2bde09ee7213e42a82f594dff16daecfa2a75dae479f6ecbacd213b9f476a03121e6602
|
|
7
|
+
data.tar.gz: b8966756b2582528fc4e4c5378e8944b9b276c706160f23dcaa8e9912eb6ba9d70e1f07dc2270ba97dd3ca8ccbe4e1355fd400b88910c7a9414e534540733256
|
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
data/Gemfile.lock
CHANGED
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
|
|
|
@@ -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
|
-
|
|
23
|
+
construct_with_hash(files, temp_folder)
|
|
24
24
|
elsif files.respond_to? :each
|
|
25
|
-
|
|
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)) }
|
|
@@ -117,7 +127,7 @@ module ActiveStorage
|
|
|
117
127
|
end
|
|
118
128
|
|
|
119
129
|
File.read(temp_file.path)
|
|
120
|
-
|
|
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.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexandre Rousseau
|
|
@@ -98,6 +98,7 @@ files:
|
|
|
98
98
|
- ".github/workflows/ci.yml"
|
|
99
99
|
- ".gitignore"
|
|
100
100
|
- ".travis.yml"
|
|
101
|
+
- AGENTS.md
|
|
101
102
|
- CHANGELOG.yml
|
|
102
103
|
- CODE_OF_CONDUCT.md
|
|
103
104
|
- Gemfile
|