Repository navigation
Expose compiled selectors as a public selection tree - #2
Merged
Merged
Conversation
CompiledMask#selection_tree returns the root SelectionTree, and SelectionTree and Selection are public constants. Their readers (named, wildcard, selection_for, leaf?, children) let an application walk a selector against a response schema and reject fields it does not declare, which the projector alone cannot do because it only ever sees data. Construction and merging stay internal (@api private). Bump to 0.2.0. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
The gem does not use YARD; keep the prose that explains behavior and remove the @param/@return/@raise/@api markup, including the tags that predate the selection tree API. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
Drop class summaries and comments that restate the code; condense the ones that explain a non-obvious decision (null passthrough, leaf-wins merging, wildcard folding, the LimitError hierarchy, the dashed entry file, nil selection trees). Disable Style/Documentation to match. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55
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
Adds a read-only way to inspect a compiled selector, so an application that has a response schema can reject selectors naming fields the schema does not declare. The projector alone cannot do that: it only ever sees response data, and a field absent from one response is not the same as a field that does not exist.
JsonMask::CompiledMask#selection_treereturns the rootJsonMask::SelectionTree(nilfor a blank selector, which passes values through).JsonMask::SelectionTreeandJsonMask::Selectionare now public constants. Public readers:SelectionTree#named(unescaped name →Selection),#wildcard, and#selection_for(key)(what the projector applies, wildcard merged);Selection#leaf?and#children.SelectionTree.empty/.single/#merge,Selection.leaf/#merge) remain internal to the parser; the class comments say so. The gem does not use YARD, so the pre-existing@param/@return/@raisetags injson_mask.rbandcompiled_mask.rbare replaced with plain comments as well.No behavior change to parsing or projection.
Motivation
The Wistia MCP server's
fieldsargument is backed by this gem. Agents sometimes guess field names that do not exist and get silently empty responses. Strict validation against each tool's OpenAPI output schema will live in the wistia repo; this PR gives it the traversal API it needs without teaching the gem JSON Schema.Testing
bundle exec rake(Minitest + RuboCop) passes locally on Ruby 3.4.9: 41 runs, 0 failures, no offenses.selection_forwith String and Symbol keys, blank selectors, and a schema-validation walk mirroring the README example.bundle exec rake buildproducesjson-mask-0.2.0.gem.🤖 Generated with Claude Code
https://claude.ai/code/session_01ALGXui8ksphAfb5D7ifG55