feat(attachable): expand the image shortcut in the type key - #18
Merged
Conversation
- `type: 'image'` / `type: :image` expands lazily at query time against ActiveStorage.variable_content_types | web_image_content_types — never frozen at boot, and the lambda only runs once the model proved it has real attachments, so the gem still loads without ActiveStorage - a real content type always carries a slash, so the shortcut name is unambiguous; an unknown literal stays a plain equality that matches nothing (never converted into a silent no-op), an unknown symbol narrows nothing; shortcuts compose inside arrays next to literals
📊 Code Quality Report
🔍 Complexity / duplication score increased — review the deltas above. 🔍 All 75 reek smells on this PR
📊 Flog complexity breakdown📊 Flay duplication breakdown |
🛡️ RuboCop: 0 offenses (0)
✅ No RuboCop offenses. |
🛡️ Coverage Report: 100.0% (0.0%)
✅ All changes are tested. Changed files
|
🛡️ Documentation Quality: 100.0% (0.0%)
✅ Documentation quality above threshold. Changed files
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The
type: :imageshortcut validated after #17: instead of enumerating MIME types by hand,filters[document][type]=imageexpands against ActiveStorage's own configured lists.Changes
TYPE_SHORTCUTS:'image'(accepted as Symbol or String — query strings only carry strings, and a real content type always has a slash, so the name is unambiguous) expands lazily at query time againstActiveStorage.variable_content_types | web_image_content_types; the lambda only runs once the model proved it has real attachments, so the gem still loads without ActiveStoragetype: ['image', 'application/pdf'])'garbage') stays a plain equality that matches nothing — a legitimate empty result, never converted into a silent no-op; an unknown symbol (:video) narrows nothingimageships: the two lists above are the only media-category lists ActiveStorage exposes (content_types_to_serve_as_binary/content_types_allowed_inlineare serving-policy lists, not categories)How to Test
bundle exec rakeContract.filterable(filters: { document: { type: 'image' } })→ blobs dont le content_type est dans les listes AS ;type: 'garbage'→ résultat vide ;type: :video→ relation intacte