feat(matchable): add whitelisted partial matching - #21
Merged
Conversation
- `matchable :reference` exposes starts_with/ends_with/contains under `filters[<attribute>]` — three distinct keys so the sargable prefix variant is distinguishable from the full-scan ones, never a catch-all like - the term is LIKE-escaped through sanitize_sql_like (user % and _ match literally) and the wildcard placement is fixed by the key: the caller never controls the pattern - arel matches, case insensitive by default (ILIKE on PostgreSQL); `matchable :code, case_sensitive: true` opts a declaration into sensitivity — the option is peeled from the declaration hash, so it coexists with aliases without the kwargs capture pitfall; case_sensitive is a reserved word, documented - association targets, aliasing, inheritance, applied_filters and the declarations validator all come from the existing machinery
🛡️ Documentation Quality: 100.0% (0.0%)
✅ Documentation quality above threshold. Changed files
|
📊 Code Quality Report
🔍 7 new reek smells introduced — review below. 🔍 7 new reek smells introduced by this PR
🔍 All 85 reek smells on this PR
📊 Flog complexity breakdown📊 Flay duplication breakdown |
🛡️ Coverage Report: 100.0% (0.0%)
✅ All changes are tested. Changed files
|
🛡️ RuboCop: 0 offenses (0)
✅ No RuboCop offenses. |
- the reserved `filters[<attribute>][case_sensitive]` key overrides the declaration either way: strict true or bare key switches on, explicit false switches off — even on an attribute declared sensitive — and anything else falls back to the declaration - the boolean-param vocabulary moves to one home: Togglable gains FALSE_VALUES and toggled_off?, Attachable's local copy is gone
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 last idea from the gem-landscape review, with every precaution it flagged:
matchable :referenceexposes partial matching as three distinct keys underfilters[<attribute>], so the sargable prefix variant is distinguishable from the full-scan ones — never a catch-alllike.Changes
starts_with(LIKE 'term%', index-friendly),ends_with(LIKE '%term'),contains(LIKE '%term%'); ninth declaration DSL with aliasing, inheritance, association targets,applied_filtersand validator support all inherited from the existing machinery (Target.narrow,acceptedpattern,KINDS)sanitize_sql_like— a user%/_matches literally (spec-locked with'%','0%','A_B'), and the wildcard placement is fixed by the declarative key: no filterameter-stylepartial: :dynamicmatches, case insensitive by default (ILIKEon PostgreSQL, spec-proven via the PostgreSQL visitor);matchable :code, case_sensitive: trueopts a declaration into sensitivity — the option is peeled from the declaration hash so it coexists with aliases without the Ruby kwargs-capture pitfall (case_sensitiveis a reserved word, documented); end-to-end sensitive spec via SQLite'sPRAGMA case_sensitive_likefilters[<attribute>][case_sensitive]— strict true or bare key switches on, explicit false switches off (even on a declared-sensitive attribute), anything else falls back to the declaration; the boolean-param vocabulary (TRUE_VALUES/FALSE_VALUES) now lives in one home,TogglableHow to Test
bundle exec rakeMovementDetail.filterable(filters: { reference: { starts_with: 'INV' } })→LIKE 'INV%'(échappé) ;{ contains: '%' }→ seules les lignes contenant un % littéral ;{ starts_with: 'INV', case_sensitive: true }→LIKEau lieu d'ILIKEsur PostgreSQL ;case_sensitive: 'false'sur un attribut déclaré sensible →ILIKE