Skip to content

Commit b2f64ee

Browse files
committed
:with
1 parent 97bbc0f commit b2f64ee

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* [#2667](https://github.com/ruby-grape/grape/pull/2667): Skip instrumentation in run_validators when no validators present - [@ericproulx](https://github.com/ericproulx).
1313
* [#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).
1414
* [#2671](https://github.com/ruby-grape/grape/pull/2671): Use ruby 3.1 shorthand kwargs syntax - [@ericproulx](https://github.com/ericproulx).
15+
* [#2672](https://github.com/ruby-grape/grape/pull/2672): Minor ruby optimizations - [@ericproulx](https://github.com/ericproulx).
1516
* Your contribution here.
1617

1718
#### Fixes

lib/grape/dsl/parameters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def optional(*attrs, **opts, &block)
161161
# @param (see #requires)
162162
# @option (see #requires)
163163
def with(**opts, &)
164-
new_group_attrs = [@group, opts].compact.reduce(&:deep_merge)
164+
new_group_attrs = @group&.deep_merge(opts) || opts
165165
new_group_scope(new_group_attrs, &)
166166
end
167167

lib/grape/router.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ def recognize_path(input)
7676
any.endpoint
7777
end
7878

79+
DEFAULT_RESPONSE_HEADERS = Grape::Util::Header.new.merge('X-Cascade' => 'pass').freeze
80+
DEFAULT_RESPONSE_BODY = ['404 Not Found'].freeze
81+
7982
private
8083

8184
def identity(input, method, env)
@@ -146,8 +149,7 @@ def with_optimization
146149
end
147150

148151
def default_response
149-
headers = Grape::Util::Header.new.merge('X-Cascade' => 'pass')
150-
[404, headers, ['404 Not Found']]
152+
[404, DEFAULT_RESPONSE_HEADERS.dup, DEFAULT_RESPONSE_BODY.dup]
151153
end
152154

153155
def match?(input, method)

lib/grape/util/inheritable_setting.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def inherit_from(parent)
5555
namespace_reverse_stackable.inherited_values = parent.namespace_reverse_stackable
5656
self.route = parent.route.merge(route)
5757

58-
point_in_time_copies.map { |cloned_one| cloned_one.inherit_from parent }
58+
point_in_time_copies.each { |cloned_one| cloned_one.inherit_from parent }
5959
end
6060

6161
# Create a point-in-time copy of this settings instance, with clones of

0 commit comments

Comments
 (0)