Skip to content

Replace .tap usages in lib/ with explicit local variables#2701

Open
ericproulx wants to merge 1 commit intomasterfrom
refactor/replace-tap-usages
Open

Replace .tap usages in lib/ with explicit local variables#2701
ericproulx wants to merge 1 commit intomasterfrom
refactor/replace-tap-usages

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

Summary

`.tap` is idiomatic when you want to perform side effects on a value and return the receiver unchanged, but most uses in `lib/` were a ceremony for "build a fresh value, mutate it a bit, return it" — clearer as plain locals. Refactor across 11 files:

File Before After
lib/grape/path.rb `[].tap { ... }` local + explicit return
lib/grape/api.rb `Class.new.tap { ... }` local + explicit return
lib/grape/middleware/auth/base.rb `.tap` for nil-check assign-then-raise
lib/grape/middleware/stack.rb `Rack::Builder.new.tap` local + explicit return
lib/grape/util/inheritable_setting.rb `self.class.new.tap` local + explicit return
lib/grape/util/base_inheritable.rb `keys.tap { concat + uniq! }` `(a + b).uniq` with guard clause
lib/grape/validations/params_documentation.rb `{}.tap` hash build-up local + explicit return
lib/grape/error_formatter/txt.rb `.tap … .join` local, then join
lib/grape/dsl/settings.rb `
lib/grape/dsl/helpers.rb `Module.new.tap` (×2) local

Drive-by: `handler.instance_of?(Symbol)` → `handler.is_a?(Symbol)` in `Middleware::Error#run_rescue_handler` for consistency with the rest of the file. Symbol can't be subclassed in MRI, so the two are behaviorally equivalent here.

Test plan

  • `bundle exec rubocop lib/` — clean (158 files, no offenses)
  • `bundle exec rspec` — full suite green (2,254 examples)

🤖 Generated with Claude Code

@ericproulx ericproulx force-pushed the refactor/replace-tap-usages branch from 71c9288 to 095458a Compare May 8, 2026 11:59
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 8, 2026

Danger Report

No issues found.

View run

@ericproulx ericproulx requested review from dblock May 8, 2026 15:37
`.tap` is idiomatic when you want to perform side effects on a value
and return the value unchanged, but most uses in lib/ were just a
ceremony for "build up a fresh value, then return it" — clearer as
plain locals.

Refactors across 11 files:
- `[].tap { |parts| ... }` → local + explicit return
- `Class.new.tap { |instance| ... }` → local + explicit return
- `Strategies[type].tap { raise unless ... }` → assign-then-raise
- `Rack::Builder.new.tap { ... }` → local + explicit return
- `self.class.new.tap { |s| ... }` → local + explicit return
- `keys.tap { concat + uniq! }` → `(a + b).uniq` with guard clause
- `{}.tap { |details| ... }` → local + explicit return
- `Array.wrap(x).tap { ... }.join(...)` → local, then join
- `Module.new.tap { |mod| ... }` → local + explicit return
- `||= …new.tap { … }` memoization → early-return memoization

Drive-by: replace `handler.instance_of?(Symbol)` with
`handler.is_a?(Symbol)` in `Middleware::Error#run_rescue_handler`
for consistency with the rest of the file (Symbol can't be
subclassed, so the two are behaviorally equivalent here).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the refactor/replace-tap-usages branch from 095458a to c210eea Compare May 8, 2026 18:02
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.

1 participant