Skip to content

Commit 97bbc0f

Browse files
ericproulxclaude
andcommitted
Use Ruby 3.1 shorthand kwargs syntax across the codebase
Replace redundant `key: key` kwargs with the shorthand `key:` form where the local variable name matches the keyword argument name. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 08c9253 commit 97bbc0f

24 files changed

Lines changed: 40 additions & 39 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* [#2657](https://github.com/ruby-grape/grape/pull/2657): Instantiate validators at definition time - [@ericproulx](https://github.com/ericproulx).
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).
14+
* [#2671](https://github.com/ruby-grape/grape/pull/2671): Use ruby 3.1 shorthand kwargs syntax - [@ericproulx](https://github.com/ericproulx).
1415
* Your contribution here.
1516

1617
#### Fixes

lib/grape/api.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def initial_setup(base_instance_parent)
4444
def override_all_methods!
4545
(base_instance.methods - Class.methods - NON_OVERRIDABLE).each do |method_override|
4646
define_singleton_method(method_override) do |*args, **kwargs, &block|
47-
add_setup(method: method_override, args: args, kwargs: kwargs, block: block)
47+
add_setup(method: method_override, args:, kwargs:, block:)
4848
end
4949
end
5050
end

lib/grape/api/instance.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def collect_route_config_per_pattern(all_routes)
170170
allow_header = namespace_inheritable[:do_not_route_options] ? allowed_methods : [Rack::OPTIONS] | allowed_methods
171171
last_route.app.options[:options_route_enabled] = true unless namespace_inheritable[:do_not_route_options] || allowed_methods.include?(Rack::OPTIONS)
172172

173-
greedy_route = Grape::Router::GreedyRoute.new(last_route.pattern, endpoint: last_route.app, allow_header: allow_header)
173+
greedy_route = Grape::Router::GreedyRoute.new(last_route.pattern, endpoint: last_route.app, allow_header:)
174174
@router.associate_routes(greedy_route)
175175
end
176176
end

lib/grape/declared_params_handler.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ def initialize(include_missing: true, evaluate_given: false, stringify: false, c
1212
def call(passed_params, declared_params, route_params, renamed_params)
1313
recursive_declared(
1414
passed_params,
15-
declared_params: declared_params,
16-
route_params: route_params,
17-
renamed_params: renamed_params
15+
declared_params:,
16+
route_params:,
17+
renamed_params:
1818
)
1919
end
2020

lib/grape/dsl/inside_route.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ def error!(message, status = nil, additional_headers = nil, backtrace = nil, ori
2929
status = self.status(status || inheritable_setting.namespace_inheritable[:default_error_status])
3030
headers = additional_headers.present? ? header.merge(additional_headers) : header
3131
throw :error,
32-
message: message,
33-
status: status,
34-
headers: headers,
35-
backtrace: backtrace,
36-
original_exception: original_exception
32+
message:,
33+
status:,
34+
headers:,
35+
backtrace:,
36+
original_exception:
3737
end
3838

3939
# Redirect to a new url.

lib/grape/dsl/routing.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ def mount(mounts, *opts)
136136
endpoints << Grape::Endpoint.new(
137137
in_setting,
138138
method: :any,
139-
path: path,
140-
app: app,
139+
path:,
140+
app:,
141141
route_options: { anchor: false },
142142
forward_match: !app.respond_to?(:inheritable_setting),
143143
for: self
@@ -167,7 +167,7 @@ def route(methods, paths = ['/'], route_options = {}, &)
167167

168168
new_endpoint = Grape::Endpoint.new(
169169
inheritable_setting,
170-
method: method,
170+
method:,
171171
path: paths,
172172
for: self,
173173
route_options: all_route_options,

lib/grape/endpoint.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def inspect
158158
protected
159159

160160
def run
161-
ActiveSupport::Notifications.instrument('endpoint_run.grape', endpoint: self, env: env) do
161+
ActiveSupport::Notifications.instrument('endpoint_run.grape', endpoint: self, env:) do
162162
@request = Grape::Request.new(env, build_params_with: inheritable_setting.namespace_inheritable[:build_params_with])
163163
begin
164164
self.class.run_before_each(self)
@@ -229,7 +229,7 @@ def run_validators(request:)
229229
def run_filters(filters, type = :other)
230230
return unless filters
231231

232-
ActiveSupport::Notifications.instrument('endpoint_run_filters.grape', endpoint: self, filters: filters, type: type) do
232+
ActiveSupport::Notifications.instrument('endpoint_run_filters.grape', endpoint: self, filters:, type:) do
233233
filters.each { |filter| instance_eval(&filter) }
234234
end
235235
end
@@ -316,15 +316,15 @@ def build_stack
316316
stack.use Rack::Head
317317
stack.use Rack::Lint if lint?
318318
stack.use Grape::Middleware::Error,
319-
format: format,
320-
content_types: content_types,
319+
format:,
320+
content_types:,
321321
default_status: inheritable_setting.namespace_inheritable[:default_error_status],
322322
rescue_all: inheritable_setting.namespace_inheritable[:rescue_all],
323323
rescue_grape_exceptions: inheritable_setting.namespace_inheritable[:rescue_grape_exceptions],
324324
default_error_formatter: inheritable_setting.namespace_inheritable[:default_error_formatter],
325325
error_formatters: inheritable_setting.namespace_stackable_with_hash(:error_formatters),
326326
rescue_options: inheritable_setting.namespace_stackable_with_hash(:rescue_options),
327-
rescue_handlers: rescue_handlers,
327+
rescue_handlers:,
328328
base_only_rescue_handlers: inheritable_setting.namespace_stackable_with_hash(:base_only_rescue_handlers),
329329
all_rescue_handler: inheritable_setting.namespace_inheritable[:all_rescue_handler],
330330
grape_exceptions_rescue_handler: inheritable_setting.namespace_inheritable[:grape_exceptions_rescue_handler]
@@ -340,9 +340,9 @@ def build_stack
340340
end
341341

342342
stack.use Grape::Middleware::Formatter,
343-
format: format,
343+
format:,
344344
default_format: inheritable_setting.namespace_inheritable[:default_format] || :txt,
345-
content_types: content_types,
345+
content_types:,
346346
formatters: inheritable_setting.namespace_stackable_with_hash(:formatters),
347347
parsers: inheritable_setting.namespace_stackable_with_hash(:parsers)
348348

lib/grape/exceptions/invalid_accept_header.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Grape
44
module Exceptions
55
class InvalidAcceptHeader < Base
66
def initialize(message, headers)
7-
super(message: compose_message(:invalid_accept_header, message: message), status: 406, headers: headers)
7+
super(message: compose_message(:invalid_accept_header, message: message), status: 406, headers:)
88
end
99
end
1010
end

lib/grape/exceptions/invalid_formatter.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Grape
44
module Exceptions
55
class InvalidFormatter < Base
66
def initialize(klass, to_format)
7-
super(message: compose_message(:invalid_formatter, klass: klass, to_format: to_format))
7+
super(message: compose_message(:invalid_formatter, klass:, to_format:))
88
end
99
end
1010
end

lib/grape/exceptions/invalid_version_header.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module Grape
44
module Exceptions
55
class InvalidVersionHeader < Base
66
def initialize(message, headers)
7-
super(message: compose_message(:invalid_version_header, message: message), status: 406, headers: headers)
7+
super(message: compose_message(:invalid_version_header, message: message), status: 406, headers:)
88
end
99
end
1010
end

0 commit comments

Comments
 (0)