Skip to content

Add Entity.[] for Grape >= 3.2 param type compatibility#394

Open
numbata wants to merge 3 commits intomasterfrom
fix/grape-3.2-coercion-compat
Open

Add Entity.[] for Grape >= 3.2 param type compatibility#394
numbata wants to merge 3 commits intomasterfrom
fix/grape-3.2-coercion-compat

Conversation

@numbata
Copy link
Copy Markdown
Collaborator

@numbata numbata commented Apr 8, 2026

Summary

Grape 3.2 requires all param types to respond_to?(:[]) in Grape::DryTypes.wrapped_dry_types_const_get. Entity classes used as param types (type: UserEntity) crash at route definition time with ArgumentError: type UserEntity should support coercion via [].

This adds a pass-through [] class method to Grape::Entity that satisfies the check without altering any existing behavior.

numbata added 3 commits April 9, 2026 00:46
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.
@numbata numbata requested a review from Copilot April 8, 2026 23:24
@numbata numbata self-assigned this Apr 8, 2026
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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’s respond_to?(:[]) requirement.
  • Add specs covering .[] behavior (including inheritance) and modernize several collection assertions (grep_v, all?(Class)).
  • Document the fix in CHANGELOG.md and update .rubocop_todo.yml for 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants