feat(concern): add declarative default filters - #14
Merged
Conversation
- `default_filters sort: '-value_date'` declares default filter params, merged under the request's filters: an absent key falls back to its default, a present key — even blank — suppresses it - a Proc default is evaluated lazily at each call (Date.current is computed at query time, not at declaration), returning nil withdraws the default; defaults go through the same whitelisted fold, so a default on an undeclared name narrows nothing - filterable and applied_filters now share a single effective_filters helper, so the report always reflects what the fold received; both hand filters a HashWithIndifferentAccess uniformly (previously raw ActionController::Parameters could reach custom filters) - opt-in only: with no declared defaults the engine behaves as before
📊 Code Quality Report
🔍 7 new reek smells introduced — review below. 🔍 7 new reek smells introduced by this PR
✅ 2 reek smells resolved by this PRThe exact list isn't shown — these smells are gone, that's what matters. 🔍 All 45 reek smells on this PR
📊 Flog complexity breakdown📊 Flay duplication breakdown |
🛡️ Documentation Quality: 100.0% (0.0%)
✅ Documentation quality above threshold. Changed files
|
🛡️ Coverage Report: 100.0% (0.0%)
✅ All changes are tested. Changed files
|
🛡️ RuboCop: 0 offenses (0)
✅ No RuboCop offenses. |
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
Last major item from the gem-landscape backlog (has_scope's
default:transposed at the engine level):default_filters sort: '-value_date'declares default filter params covering default sort and default filter values in one mechanism — opt-in only, never an implicit fallback.Changes
default_filters(hash)+ inheriteddefault_filter_paramsregistry onFilterable::Concern; defaults are merged under the request'sfilters, so an absent key falls back to its default and a present key — even blank — suppresses it (the caller expressed intent for that key)Procdefault is evaluated lazily at each call (Date.currentcomputed at query time, not at declaration — the classic frozen-time bug); aProcreturningnilwithdraws its defaultfilterableandapplied_filtersnow share a singleeffective_filtershelper — the report always reflects exactly what the fold received, andModel.filterable({})applies the declared defaultsHashWithIndifferentAccess(previously a rawActionController::Parameterscould reach custom filters); all built-in filters already handled both, the whole suite passes unchangedHow to Test
bundle exec rakemodel.default_filters(sort: '-value_date')puismodel.filterable({})→ relation triée desc ;model.filterable(filters: { sort: '+value_date' })→ la requête gagne ;model.applied_filters({})→{ 'sort' => '-value_date' }