Skip to content

Less active support concern #2574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 23, 2025

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Jun 22, 2025

Refactor DSL modules by removing unnecessary ActiveSupport::Concern

This PR refactors the Grape DSL modules to remove unnecessary ActiveSupport::Concern usage and simplify the codebase architecture.

Changes

DSL Module Refactoring

  • Removed ActiveSupport::Concern from all DSL modules where it was unnecessary
  • Simplified module structure by removing included and extended callbacks that weren't providing value
  • Streamlined inheritance by using direct module inclusion instead of concern-based approach

Affected Modules

  • Grape::DSL::Callbacks - Simplified callback registration
  • Grape::DSL::Helpers - Streamlined helper module inclusion
  • Grape::DSL::Routing - Cleaner route definition and mounting
  • Grape::DSL::RequestResponse - Simplified request/response handling
  • Grape::DSL::Settings - Cleaner configuration management
  • Grape::DSL::Validations - Streamlined validation setup
  • Grape::DSL::Middleware - Simplified middleware configuration
  • Grape::DSL::Parameters - Cleaner parameter handling
  • Grape::DSL::Logger - Simplified logging setup
  • Grape::DSL::InsideRoute - Streamlined route execution
  • Grape::DSL::Desc - Simplified description handling
  • Grape::DSL::Configuration - Cleaner configuration management

Code Cleanup

  • Removed unused code including the invalid_value short name that wasn't being used
  • Simplified API structure by removing unnecessary abstraction layers
  • Improved maintainability by reducing complexity in DSL modules

Testing

  • Updated all related specs to work with the new simplified structure
  • Enhanced test coverage for the refactored modules
  • Maintained backward compatibility - all existing functionality works as expected

Benefits

Performance

  • Reduced memory overhead by removing unnecessary concern infrastructure
  • Faster module loading due to simplified inheritance chain
  • Improved startup time for Grape applications

Maintainability

  • Cleaner code structure that's easier to understand and modify
  • Reduced complexity in DSL module interactions
  • Better separation of concerns without unnecessary abstraction layers

Compatibility

  • No breaking changes - all existing APIs continue to work
  • Same functionality with improved internal implementation
  • Backward compatible with existing Grape applications

Impact

This refactoring is a non-breaking change that improves the internal architecture of Grape's DSL system. All existing Grape applications will continue to work without modification, but will benefit from:

  • Improved performance
  • Better maintainability
  • Cleaner codebase
  • Reduced complexity

Testing

  • All existing tests pass
  • No regressions in functionality
  • Improved test coverage for refactored modules
  • Integration tests confirm backward compatibility

@ericproulx ericproulx requested a review from Copilot June 22, 2025 11:20
Copy link
Contributor

@Copilot 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 refactors several DSL modules by switching from instance inclusion to class extension, removes reliance on ActiveSupport::Concern, and cleans up deprecated or redundant code. Key changes include:

  • Removal of legacy tests for Grape::DSL::Validations in the integration specs.
  • Updating DSL modules and helper methods across multiple files to use concise patterns and extend modules.
  • Eliminating deprecated code files and streamlining settings and middleware definitions.

Reviewed Changes

Copilot reviewed 29 out of 29 changed files in this pull request and generated 1 comment.

File Description
spec/integration/dry_validation/dry_validation_spec.rb Removed the Grape::DSL::Validations tests to deprecate inactive support
spec/grape/validations/validators/coerce_validator_spec.rb Updated to refer to Grape::Validations::Types::InvalidValue for consistency
spec/grape/dsl/* and lib/grape/dsl/* Converted many modules from include to extend and removed ActiveSupport::Concern usage, among other DSL cleanup changes
lib/grape/api/* Simplified API instance logger handling and removed deprecated helper definitions
Comments suppressed due to low confidence (1)

spec/integration/dry_validation/dry_validation_spec.rb:3

  • The removal of tests for Grape::DSL::Validations may reduce coverage; please ensure that the new behavior is adequately tested elsewhere.
describe 'Dry::Schema', if: defined?(Dry::Schema) do

@ericproulx ericproulx force-pushed the less_active_support_concern branch from 002f15b to 369445c Compare June 22, 2025 11:33
@ericproulx ericproulx marked this pull request as ready for review June 22, 2025 11:39
@ericproulx ericproulx force-pushed the less_active_support_concern branch 6 times, most recently from 2ff6075 to 4a89c18 Compare June 22, 2025 12:21
it 'evaluates block' do
expect { subject.params { raise 'foo' } }.to raise_error RuntimeError, 'foo'
def self.namespace_stackable_hash
@namespace_stackable_hash ||= Hash.new do |hash, key|
Copy link
Member

@dblock dblock Jun 22, 2025

Choose a reason for hiding this comment

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

This causes a side effect, doesn't it? Clear it? A few other instances of the same, let's make sure tests don't leak.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've done the same pattern elsewhere. Since some module are dependent, I need to recreate the functions in the anonymous class.
This won't leak

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since some modules are dependent, i'll check if I can combine them.

@ericproulx ericproulx force-pushed the less_active_support_concern branch from 4a89c18 to 50875c2 Compare June 22, 2025 16:46
@grape-bot
Copy link

1 Warning
⚠️ Unless you're refactoring existing code or improving documentation, please update CHANGELOG.md.

Here's an example of a CHANGELOG.md entry:

* [#2574](https://github.com/ruby-grape/grape/pull/2574): Less active support concern - [@ericproulx](https://github.com/ericproulx).

Generated by 🚫 Danger

@ericproulx ericproulx force-pushed the less_active_support_concern branch 3 times, most recently from b22431a to c5771ff Compare June 22, 2025 17:12
Remove invalid value short name (not used)
@ericproulx ericproulx force-pushed the less_active_support_concern branch from c5771ff to 0df0860 Compare June 22, 2025 17:17
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

This looks good.

@dblock dblock merged commit b0b8dee into ruby-grape:master Jun 23, 2025
47 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.

3 participants