Combine predefined activestorage attachment variants #46242
+48
−6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation / Background
Sometimes you will want to combine predefined-variants, like rotate and thumb:
Until now, you could only use 1 variant. If you would like to combine multiple variants, you would have to explicitly create all possible combinations, which becomes quite cluttered quick, e.g.:
This PR adds support for combining multiple variants.
This Pull Request has been created because we use activestorage a lot and sometimes want to combine predefined-variants.
Detail
This Pull Request changes the way that ActiveStorage::Attachment looks up transformations. It is backwards compatible, but allows users to define more than 1 predefined variant.
Before:
After:
Additional information
I chose to use some recursion in the lookup process, it works just fine, but might be hard to read for some. Could write this out in a more explicit way.
Checklist
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
main
(if not - rebase it).