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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2e8bd7c03d00db97d4d1079809a0bc5776055f6d493b2199a6366c8bdb3a55e9
4
- data.tar.gz: 77a509201b03aa9b7921c84f0c5f042a5f974136b9c9949fc4ecd286e9afe5ce
3
+ metadata.gz: 3cb438270e8304e1c4feea19d3c14c254cdf819978eeb82cb58a74b9bbcdf05e
4
+ data.tar.gz: e8ca7ec1429aa7b3d770c7ca671150ea039da739095ccea4994d161a6e583130
5
5
  SHA512:
6
- metadata.gz: 1de5bc05baf0497ed25b24efa19704dd7b334a707263fec4ae249bf489413810218e1df435d5be89102281f4a470d0c44970b01e3e4984b6e8c8b9f0bdc63f23
7
- data.tar.gz: 14d1c1a5d5134ae42bcfa87fbf2f9be3498f02677b7f9fbdddee046ad2bbd9c96ea6baf655347106161030a18197a314b88cab366635ca032e4896a0f30028ed
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
@@ -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,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- active_storage-send_zip (0.4.0)
4
+ active_storage-send_zip (0.5.0)
5
5
  rails (> 5.2)
6
6
  rubyzip (>= 2.1.0, < 4.0)
7
7
 
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
 
@@ -3,6 +3,6 @@
3
3
  module ActiveStorage
4
4
  module SendZip
5
5
  # The version of this gem
6
- VERSION = '0.4.0'
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)) }
@@ -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.4.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