From 8ef110c1496adc3de0f732132f62733881d96b70 Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Sun, 27 Jul 2025 16:33:28 +0200 Subject: [PATCH] Just keep `helpers` method in the public scope. --- CHANGELOG.md | 1 + lib/grape/dsl/helpers.rb | 2 +- spec/grape/dsl/helpers_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index dd24c4ef6..c282fd948 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ #### Fixes +* [#2586](https://github.com/ruby-grape/grape/pull/2586): Limit helpers DSL public scope - [@ericproulx](https://github.com/ericproulx). * Your contribution here. ### 2.4.0 (2025-06-18) diff --git a/lib/grape/dsl/helpers.rb b/lib/grape/dsl/helpers.rb index 4338ff1ac..e61c32a27 100644 --- a/lib/grape/dsl/helpers.rb +++ b/lib/grape/dsl/helpers.rb @@ -34,7 +34,7 @@ def helpers(*new_modules, &block) include_all_in_scope if !block && new_modules.empty? end - protected + private def include_new_modules(modules) return if modules.empty? diff --git a/spec/grape/dsl/helpers_spec.rb b/spec/grape/dsl/helpers_spec.rb index a1b07bd5c..b046e9222 100644 --- a/spec/grape/dsl/helpers_spec.rb +++ b/spec/grape/dsl/helpers_spec.rb @@ -113,5 +113,11 @@ def test expect { api_class }.not_to raise_exception end end + + context 'public scope' do + it 'returns helpers only' do + expect(Class.new { extend Grape::DSL::Helpers }.singleton_methods - Class.methods).to contain_exactly(:helpers) + end + end end end