Readability pass: guard clauses + small refactors across lib/#2741
Open
ericproulx wants to merge 1 commit into
Open
Readability pass: guard clauses + small refactors across lib/#2741ericproulx wants to merge 1 commit into
ericproulx wants to merge 1 commit into
Conversation
02c0571 to
da11b68
Compare
Danger ReportNo issues found. |
dblock
approved these changes
May 25, 2026
Mostly cosmetic, no behavior change except where noted.
Guard-clause lifts (lift the short-circuit above the if/elsif/else,
let the main flow sit at top indentation):
- `Grape::DSL::Logger#logger`, `DSL::InsideRoute#stream`/`#return_no_content`
- `Grape::Formatter::SerializableHash#serialize`
- `Grape::Middleware::Base#merge_default_options`
- `Grape::Middleware::Error#redispatch`
- `Grape::Middleware::Formatter` (`call!`, `negotiate_content_type`)
- `Grape::Router::Pattern#build_path_from_pattern`
- `Grape::ServeStream::SendfileResponse#respond_to?`
- `Grape::Validations::ParamsScope#configure_declared_params`
- `Grape::Exceptions::ErrorResponse.coerce` (case/when reformatted)
Small extractions:
- `DSL::Entity#entity_class_for_obj`: extract `object_class(object)`
private helper.
- `DSL::InsideRoute#status`: collapse Symbol/Integer branches and
extract `default_status` private helper. Error message for an
unknown status symbol now bubbles up `Rack::Utils.status_code`'s
own message ("Unrecognized status code :foo_bar") instead of
Grape's pre-validation message ("Status code :foo_bar is invalid.");
spec updated.
- `DSL::InsideRoute#stream`: extract `stream_body(value)` private
helper.
- `DSL::InsideRoute#return_no_content`: drop the redundant `status 204`
call — `body false` already sets it via the `body` setter.
Minor: `return nil unless` → `return unless` in `Grape::API::Boolean.build`
and `PrimitiveCoercer#call`.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
da11b68 to
4c9bbaf
Compare
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
Mostly cosmetic. Lifts if/elsif/else chains into guard clauses across
dsl/,middleware/,router/,formatter/, and a few small extractions. No behavior change except where noted below.Guard-clause lifts (the short-circuit moves above the
if, main flow sits at top indentation):DSL::Logger#logger,DSL::InsideRoute#stream/#return_no_contentFormatter::SerializableHash#serializeMiddleware::Base#merge_default_optionsMiddleware::Error#redispatchMiddleware::Formatter#call!/#negotiate_content_typeRouter::Pattern#build_path_from_patternServeStream::SendfileResponse#respond_to?Validations::ParamsScope#configure_declared_paramsExceptions::ErrorResponse.coerce(case/when reformatted to multi-line)Small extractions:
DSL::Entity#entity_class_for_obj: extractobject_class(object)private helper.DSL::InsideRoute#status: collapse Symbol/Integer branches; extractdefault_statusprivate helper.DSL::InsideRoute#stream: extractstream_body(value)private helper.DSL::InsideRoute#return_no_content: drop redundantstatus 204—body falsealready sets it via the setter.Tiny:
return nil unless→return unlessinGrape::API::Boolean.buildandPrimitiveCoercer#call.Behavior note
DSL::InsideRoute#statuswith an unknown symbol now raises withRack::Utils.status_code's native message ("Unrecognized status code :foo_bar") instead of Grape's pre-validation message ("Status code :foo_bar is invalid."). One spec updated to match.Test plan
bundle exec rspec— 2313 examples, 0 failuresbundle exec rubocop— clean on touched files🤖 Generated with Claude Code