From 7883931719b7fa49e8588565c4aec340f970469a Mon Sep 17 00:00:00 2001 From: Eric Proulx Date: Fri, 3 Apr 2026 19:08:40 +0200 Subject: [PATCH] :with --- CHANGELOG.md | 1 + lib/grape/dsl/parameters.rb | 2 +- lib/grape/router.rb | 6 ++++-- lib/grape/util/inheritable_setting.rb | 2 +- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62b981520..5d0c6b42d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ * [#2667](https://github.com/ruby-grape/grape/pull/2667): Skip instrumentation in run_validators when no validators present - [@ericproulx](https://github.com/ericproulx). * [#2670](https://github.com/ruby-grape/grape/pull/2670): Added support for Rack 3.2.6 and better handling to rack exceptions - [@ericproulx](https://github.com/ericproulx). * [#2671](https://github.com/ruby-grape/grape/pull/2671): Use ruby 3.1 shorthand kwargs syntax - [@ericproulx](https://github.com/ericproulx). +* [#2672](https://github.com/ruby-grape/grape/pull/2672): Minor ruby optimizations - [@ericproulx](https://github.com/ericproulx). * Your contribution here. #### Fixes diff --git a/lib/grape/dsl/parameters.rb b/lib/grape/dsl/parameters.rb index feadbd664..b9479b18e 100644 --- a/lib/grape/dsl/parameters.rb +++ b/lib/grape/dsl/parameters.rb @@ -161,7 +161,7 @@ def optional(*attrs, **opts, &block) # @param (see #requires) # @option (see #requires) def with(**opts, &) - new_group_attrs = [@group, opts].compact.reduce(&:deep_merge) + new_group_attrs = @group&.deep_merge(opts) || opts new_group_scope(new_group_attrs, &) end diff --git a/lib/grape/router.rb b/lib/grape/router.rb index 6710c03b2..988b5f1d0 100644 --- a/lib/grape/router.rb +++ b/lib/grape/router.rb @@ -76,6 +76,9 @@ def recognize_path(input) any.endpoint end + DEFAULT_RESPONSE_HEADERS = Grape::Util::Header.new.merge('X-Cascade' => 'pass').freeze + DEFAULT_RESPONSE_BODY = ['404 Not Found'].freeze + private def identity(input, method, env) @@ -146,8 +149,7 @@ def with_optimization end def default_response - headers = Grape::Util::Header.new.merge('X-Cascade' => 'pass') - [404, headers, ['404 Not Found']] + [404, DEFAULT_RESPONSE_HEADERS.dup, DEFAULT_RESPONSE_BODY.dup] end def match?(input, method) diff --git a/lib/grape/util/inheritable_setting.rb b/lib/grape/util/inheritable_setting.rb index 18c8ba793..cae002774 100644 --- a/lib/grape/util/inheritable_setting.rb +++ b/lib/grape/util/inheritable_setting.rb @@ -55,7 +55,7 @@ def inherit_from(parent) namespace_reverse_stackable.inherited_values = parent.namespace_reverse_stackable self.route = parent.route.merge(route) - point_in_time_copies.map { |cloned_one| cloned_one.inherit_from parent } + point_in_time_copies.each { |cloned_one| cloned_one.inherit_from parent } end # Create a point-in-time copy of this settings instance, with clones of