Skip to content

Conversation

ericproulx
Copy link
Contributor

Refactor route_setting internal usage to use inheritable_setting.route

Summary

This PR refactors the internal usage of route_setting method calls to directly use inheritable_setting.route hash access. This change improves code consistency and removes the need for the intermediate route_setting method in internal Grape code.

Changes Made

Core Library Changes

  • lib/grape/dsl/desc.rb: Replaced route_setting(:description, settings) with inheritable_setting.route[:description] = settings
  • lib/grape/dsl/inside_route.rb:
    • Replaced route_setting(:renamed_params) with inheritable_setting.route[:renamed_params]
    • Replaced route_setting(:declared_params) with inheritable_setting.route[:declared_params]
  • lib/grape/dsl/routing.rb:
    • Replaced route_setting(:description) with inheritable_setting.route[:description]
    • Fixed method handling for :any routes (changed methods to method)
  • lib/grape/endpoint.rb:
    • Replaced route_setting(:declared_params, ...) with inheritable_setting.route[:declared_params] = ...
    • Replaced route_setting(:saved_validations, ...) with inheritable_setting.route[:saved_validations] = ...
    • Updated validations method to use direct hash access
  • lib/grape/validations/params_scope.rb:
    • Replaced route_setting(:renamed_params) with inheritable_setting.route[:renamed_params]

Test Updates

  • spec/grape/dsl/desc_spec.rb: Simplified test class by extending Grape::DSL::Settings instead of manually implementing route_setting methods
  • spec/grape/dsl/routing_spec.rb: Updated test expectations to use inheritable_setting.route structure

Benefits

  1. Consistency: All internal code now uses the same pattern for accessing route settings
  2. Performance: Direct hash access is more efficient than method calls
  3. Maintainability: Reduces the number of methods that need to be maintained
  4. Clarity: Makes it clear that we're working with the inheritable setting structure

Breaking Changes

None. This is an internal refactoring that doesn't change the public API.

Testing

  • All existing tests pass
  • Test classes have been updated to use the proper inheritable_setting structure
  • No new functionality has been added, only internal implementation changes

Files Changed

  • lib/grape/dsl/desc.rb
  • lib/grape/dsl/inside_route.rb
  • lib/grape/dsl/routing.rb
  • lib/grape/endpoint.rb
  • lib/grape/validations/params_scope.rb
  • spec/grape/dsl/desc_spec.rb
  • spec/grape/dsl/routing_spec.rb

Related Issues

This refactoring is part of improving the internal architecture of Grape's route setting management system.

- Remove unset, unset_namespace_stackable, and namespace_inheritable_to_nil methods
- Simplify reset_validations! to call delete directly instead of through wrappers
- Enhance BaseInheritable#delete to accept multiple keys
- Improve without_root_prefix_and_versioning with proper ensure block cleanup
- Update tests to verify actual behavior instead of method calls

These methods were internal APIs not intended for public use. Removing them
reduces the public API surface and simplifies the codebase.
- Replace dynamic method generation with explicit method definitions
- Simplify get_or_set to work directly with setting objects instead of type symbols
- Update logger to directly access global settings for better performance
- Improve test coverage to focus on actual behavior rather than delegation
- Remove unnecessary complexity in settings DSL implementation
…tency

- Remove method indirection in Base class by using define_method for options
- Consolidate version options handling and improve initialization
- Replace strict? method calls with direct strict access
- Fix parameter_key references to use parameter method directly
- Improve version matching logic and error handling consistency
- Replace route_setting calls with direct inheritable_setting.route access
- Update desc.rb to use inheritable_setting.route[:description]
- Update inside_route.rb to use inheritable_setting.route for renamed_params and declared_params
- Update routing.rb to use inheritable_setting.route[:description] and fix method handling
- Update endpoint.rb to use inheritable_setting.route for declared_params and saved_validations
- Update params_scope.rb to use inheritable_setting.route[:renamed_params]
- Update tests to use proper inheritable_setting structure
@ericproulx ericproulx force-pushed the refactor_route_setting_internal_usage branch from c2c0887 to a8b9a8c Compare September 20, 2025 12:42
@ericproulx ericproulx marked this pull request as ready for review September 20, 2025 12:55
@dblock dblock merged commit d2d7798 into master Sep 21, 2025
93 checks passed
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