Add Entity.[] for Grape >= 3.2 param type compatibility#394
Open
Add Entity.[] for Grape >= 3.2 param type compatibility#394
Conversation
Grape 3.2 requires all param types to respond to [] for coercion. Entity classes used as param types (e.g. `type: UserEntity`) crash at route definition time because Grape::DryTypes checks respond_to?(:[]) and raises ArgumentError when it is missing. Add a pass-through [] class method that satisfies the check without altering any existing behavior.
Autocorrect SelectByKind and PredicateWithKind offenses in specs. Exclude bench/serializing.rb from Style/OneClassPerFile as it is a benchmark script that intentionally defines multiple modules.
There was a problem hiding this comment.
Pull request overview
This PR updates Grape::Entity to be compatible with Grape >= 3.2’s param type expectations by adding a no-op Entity.[] class method, preventing route-definition-time failures when an Entity class is used as a param type.
Changes:
- Add
Grape::Entity.[]as a pass-through to satisfy Grape 3.2’srespond_to?(:[])requirement. - Add specs covering
.[]behavior (including inheritance) and modernize several collection assertions (grep_v,all?(Class)). - Document the fix in
CHANGELOG.mdand update.rubocop_todo.ymlfor an existing bench file offense.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
lib/grape_entity/entity.rb |
Adds Entity.[] pass-through class method for Grape >= 3.2 param type compatibility. |
spec/grape_entity/entity_spec.rb |
Adds coverage for .[] and refactors assertions using grep_v / all?(Class). |
CHANGELOG.md |
Adds an entry describing the compatibility fix. |
.rubocop_todo.yml |
Excludes bench/serializing.rb from Style/OneClassPerFile (auto-gen config alignment). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Grape 3.2 requires all param types to
respond_to?(:[])inGrape::DryTypes.wrapped_dry_types_const_get. Entity classes used as param types (type: UserEntity) crash at route definition time withArgumentError: type UserEntity should support coercion via [].This adds a pass-through
[]class method toGrape::Entitythat satisfies the check without altering any existing behavior.