Skip to content

Readability: case/when, guard clauses, small cleanups#2684

Open
ericproulx wants to merge 1 commit intomasterfrom
chore/readability-pass
Open

Readability: case/when, guard clauses, small cleanups#2684
ericproulx wants to merge 1 commit intomasterfrom
chore/readability-pass

Conversation

@ericproulx
Copy link
Copy Markdown
Contributor

Summary

Mechanical readability refactors across validators, DSLs, and formatters. No behavior change.

  • dsl/inside_route.rb: sendfile dispatched via case/when on value type.
  • dsl/parameters.rb: map_params switched to case/when; EmptyOptionalValue simplified to a frozen Object.new; public/private method order tidied.
  • error_formatter/json.rb: wrap_message dispatched via case/when.
  • middleware/formatter.rb: guard-clause returns in ensure_content_type and read_rack_input; bodies.collectbodies.map.
  • validations/types.rb: create_coercer_instance rewritten as a priority-list of guards with comments above each branch; shared array_or_set? predicate extracted; redundant Types. prefixes dropped inside module_function Types.
  • validations/types/primitive_coercer.rb: reject? rewritten as case/when dispatching on the value's class.
  • validators/except_values_validator.rb: lift except.is_a?(Proc) to a local so it isn't recomputed.

Test plan

  • Full RSpec suite passes locally (2236 examples, 0 failures).
  • CI green.

🤖 Generated with Claude Code

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 19, 2026

Danger Report

No issues found.

View run

Mechanical readability refactors across validators, DSLs, and formatters:

- inside_route.rb: sendfile dispatched via case/when on value type.
- parameters.rb: map_params switched to case/when; EmptyOptionalValue
  simplified to a frozen Object.new; method order tidied.
- error_formatter/json.rb: wrap_message dispatched via case/when.
- middleware/formatter.rb: guard-clause returns in ensure_content_type
  and read_rack_input; bodies.collect -> bodies.map.
- validations/types.rb: create_coercer_instance rewritten as a
  priority-list of guards with comments above each branch; shared
  array_or_set? predicate extracted; redundant Types. prefix dropped.
- validations/types/primitive_coercer.rb: reject? rewritten as case/when
  with String/Array|Hash dispatch.
- validators/except_values_validator.rb: lift except.is_a?(Proc) to a
  local to avoid recomputing it.

No behavior change.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ericproulx ericproulx force-pushed the chore/readability-pass branch from 84d2c2b to 95e47c1 Compare April 19, 2026 12:58
@ericproulx ericproulx requested a review from dblock April 19, 2026 13:29
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