diff --git a/.rubocop.yml b/.rubocop.yml index 3e407d0bb..1592efee4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,6 +22,9 @@ Lint/EmptyBlock: Style/Documentation: Enabled: false +Style/HashSyntax: + EnforcedShorthandSyntax: always + Style/MultilineIfModifier: Enabled: false diff --git a/CHANGELOG.md b/CHANGELOG.md index a384d431c..62b981520 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ * [#2657](https://github.com/ruby-grape/grape/pull/2657): Instantiate validators at definition time - [@ericproulx](https://github.com/ericproulx). * [#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). * Your contribution here. #### Fixes diff --git a/lib/grape/api.rb b/lib/grape/api.rb index f8e8b7db9..581da519b 100644 --- a/lib/grape/api.rb +++ b/lib/grape/api.rb @@ -44,7 +44,7 @@ def initial_setup(base_instance_parent) def override_all_methods! (base_instance.methods - Class.methods - NON_OVERRIDABLE).each do |method_override| define_singleton_method(method_override) do |*args, **kwargs, &block| - add_setup(method: method_override, args: args, kwargs: kwargs, block: block) + add_setup(method: method_override, args:, kwargs:, block:) end end end diff --git a/lib/grape/api/instance.rb b/lib/grape/api/instance.rb index 8e081fd91..40eca7378 100644 --- a/lib/grape/api/instance.rb +++ b/lib/grape/api/instance.rb @@ -170,7 +170,7 @@ def collect_route_config_per_pattern(all_routes) allow_header = namespace_inheritable[:do_not_route_options] ? allowed_methods : [Rack::OPTIONS] | allowed_methods last_route.app.options[:options_route_enabled] = true unless namespace_inheritable[:do_not_route_options] || allowed_methods.include?(Rack::OPTIONS) - greedy_route = Grape::Router::GreedyRoute.new(last_route.pattern, endpoint: last_route.app, allow_header: allow_header) + greedy_route = Grape::Router::GreedyRoute.new(last_route.pattern, endpoint: last_route.app, allow_header:) @router.associate_routes(greedy_route) end end diff --git a/lib/grape/declared_params_handler.rb b/lib/grape/declared_params_handler.rb index fd31a4460..1b9226c67 100644 --- a/lib/grape/declared_params_handler.rb +++ b/lib/grape/declared_params_handler.rb @@ -12,9 +12,9 @@ def initialize(include_missing: true, evaluate_given: false, stringify: false, c def call(passed_params, declared_params, route_params, renamed_params) recursive_declared( passed_params, - declared_params: declared_params, - route_params: route_params, - renamed_params: renamed_params + declared_params:, + route_params:, + renamed_params: ) end diff --git a/lib/grape/dsl/declared.rb b/lib/grape/dsl/declared.rb index 7d2cfda15..8dbdd7f2b 100644 --- a/lib/grape/dsl/declared.rb +++ b/lib/grape/dsl/declared.rb @@ -23,7 +23,7 @@ def declared(passed_params, include_parent_namespaces: true, include_missing: tr raise MethodNotYetAvailable unless before_filter_passed contract_key_map = inheritable_setting.namespace_stackable[:contract_key_map] - handler = DeclaredParamsHandler.new(include_missing:, evaluate_given:, stringify:, contract_key_map: contract_key_map) + handler = DeclaredParamsHandler.new(include_missing:, evaluate_given:, stringify:, contract_key_map:) declared_params = include_parent_namespaces ? inheritable_setting.route[:declared_params] : (inheritable_setting.namespace_stackable[:declared_params].last || []) renamed_params = inheritable_setting.route[:renamed_params] || {} route_params = options.dig(:route_options, :params) || {} # options = endpoint's option diff --git a/lib/grape/dsl/desc.rb b/lib/grape/dsl/desc.rb index 7333fcf5b..852df6f96 100644 --- a/lib/grape/dsl/desc.rb +++ b/lib/grape/dsl/desc.rb @@ -55,7 +55,7 @@ def desc(description, options = {}, &config_block) endpoint_config = defined?(configuration) ? configuration : nil Grape::Util::ApiDescription.new(description, endpoint_config, &config_block).settings else - options.merge(description: description) + options.merge(description:) end inheritable_setting.namespace[:description] = settings inheritable_setting.route[:description] = settings diff --git a/lib/grape/dsl/inside_route.rb b/lib/grape/dsl/inside_route.rb index 213ac2bc2..fff856884 100644 --- a/lib/grape/dsl/inside_route.rb +++ b/lib/grape/dsl/inside_route.rb @@ -29,11 +29,11 @@ def error!(message, status = nil, additional_headers = nil, backtrace = nil, ori status = self.status(status || inheritable_setting.namespace_inheritable[:default_error_status]) headers = additional_headers.present? ? header.merge(additional_headers) : header throw :error, - message: message, - status: status, - headers: headers, - backtrace: backtrace, - original_exception: original_exception + message:, + status:, + headers:, + backtrace:, + original_exception: end # Redirect to a new url. @@ -272,7 +272,7 @@ def entity_class_for_obj(object, options) # @return the representation of the given object as done through # the given entity_class. def entity_representation_for(entity_class, object, options) - embeds = { env: env } + embeds = { env: } embeds[:version] = env[Grape::Env::API_VERSION] if env.key?(Grape::Env::API_VERSION) entity_class.represent(object, **embeds, **options) end diff --git a/lib/grape/dsl/parameters.rb b/lib/grape/dsl/parameters.rb index 2c70a9dbd..feadbd664 100644 --- a/lib/grape/dsl/parameters.rb +++ b/lib/grape/dsl/parameters.rb @@ -167,7 +167,7 @@ def with(**opts, &) %i[mutually_exclusive exactly_one_of at_least_one_of all_or_none_of].each do |validator| define_method validator do |*attrs, message: nil| - validates(attrs, validator => { value: true, message: message }) + validates(attrs, validator => { value: true, message: }) end end diff --git a/lib/grape/dsl/routing.rb b/lib/grape/dsl/routing.rb index 8782e8391..2dc9ed13a 100644 --- a/lib/grape/dsl/routing.rb +++ b/lib/grape/dsl/routing.rb @@ -136,8 +136,8 @@ def mount(mounts, *opts) endpoints << Grape::Endpoint.new( in_setting, method: :any, - path: path, - app: app, + path:, + app:, route_options: { anchor: false }, forward_match: !app.respond_to?(:inheritable_setting), for: self @@ -167,7 +167,7 @@ def route(methods, paths = ['/'], route_options = {}, &) new_endpoint = Grape::Endpoint.new( inheritable_setting, - method: method, + method:, path: paths, for: self, route_options: all_route_options, @@ -203,7 +203,7 @@ def namespace(space = nil, requirements: nil, **options, &block) within_namespace do nest(block) do - inheritable_setting.namespace_stackable[:namespace] = Grape::Namespace.new(space, requirements: requirements, **options) if space + inheritable_setting.namespace_stackable[:namespace] = Grape::Namespace.new(space, requirements:, **options) if space end end end @@ -230,7 +230,7 @@ def route_param(param, requirements: nil, type: nil, **, &) requires param, type: type end if type - namespace(":#{param}", requirements: requirements, **, &) + namespace(":#{param}", requirements:, **, &) end # @return array of defined versions diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index ec38dc633..e82099bbd 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -158,7 +158,7 @@ def inspect protected def run - ActiveSupport::Notifications.instrument('endpoint_run.grape', endpoint: self, env: env) do + ActiveSupport::Notifications.instrument('endpoint_run.grape', endpoint: self, env:) do @request = Grape::Request.new(env, build_params_with: inheritable_setting.namespace_inheritable[:build_params_with]) begin self.class.run_before_each(self) @@ -174,7 +174,7 @@ def run status 204 else run_filters before_validations, :before_validation - run_validators request: request + run_validators(request:) run_filters after_validations, :after_validation response_object = execute end @@ -210,7 +210,7 @@ def run_validators(request:) validation_errors = [] Grape::Validations::ParamScopeTracker.track do - ActiveSupport::Notifications.instrument('endpoint_run_validators.grape', endpoint: self, validators: validators, request:) do + ActiveSupport::Notifications.instrument('endpoint_run_validators.grape', endpoint: self, validators:, request:) do validators.each do |validator| validator.validate(request) rescue Grape::Exceptions::Validation => e @@ -229,7 +229,7 @@ def run_validators(request:) def run_filters(filters, type = :other) return unless filters - ActiveSupport::Notifications.instrument('endpoint_run_filters.grape', endpoint: self, filters: filters, type: type) do + ActiveSupport::Notifications.instrument('endpoint_run_filters.grape', endpoint: self, filters:, type:) do filters.each { |filter| instance_eval(&filter) } end end @@ -279,7 +279,7 @@ def to_routes def prepare_default_route_attributes(route_options) { - namespace: namespace, + namespace:, version: prepare_version(inheritable_setting.namespace_inheritable[:version]), requirements: prepare_routes_requirements(route_options[:requirements]), prefix: inheritable_setting.namespace_inheritable[:root_prefix], @@ -316,15 +316,15 @@ def build_stack stack.use Rack::Head stack.use Rack::Lint if lint? stack.use Grape::Middleware::Error, - format: format, - content_types: content_types, + format:, + content_types:, default_status: inheritable_setting.namespace_inheritable[:default_error_status], rescue_all: inheritable_setting.namespace_inheritable[:rescue_all], rescue_grape_exceptions: inheritable_setting.namespace_inheritable[:rescue_grape_exceptions], default_error_formatter: inheritable_setting.namespace_inheritable[:default_error_formatter], error_formatters: inheritable_setting.namespace_stackable_with_hash(:error_formatters), rescue_options: inheritable_setting.namespace_stackable_with_hash(:rescue_options), - rescue_handlers: rescue_handlers, + rescue_handlers:, base_only_rescue_handlers: inheritable_setting.namespace_stackable_with_hash(:base_only_rescue_handlers), all_rescue_handler: inheritable_setting.namespace_inheritable[:all_rescue_handler], grape_exceptions_rescue_handler: inheritable_setting.namespace_inheritable[:grape_exceptions_rescue_handler] @@ -340,9 +340,9 @@ def build_stack end stack.use Grape::Middleware::Formatter, - format: format, + format:, default_format: inheritable_setting.namespace_inheritable[:default_format] || :txt, - content_types: content_types, + content_types:, formatters: inheritable_setting.namespace_stackable_with_hash(:formatters), parsers: inheritable_setting.namespace_stackable_with_hash(:parsers) @@ -360,7 +360,7 @@ def build_helpers def build_response_cookies response_cookies do |name, value| - cookie_value = value.is_a?(Hash) ? value : { value: value } + cookie_value = value.is_a?(Hash) ? value : { value: } Rack::Utils.set_cookie_header! header, name, cookie_value end end diff --git a/lib/grape/error_formatter/base.rb b/lib/grape/error_formatter/base.rb index 913a5846d..3e16429aa 100644 --- a/lib/grape/error_formatter/base.rb +++ b/lib/grape/error_formatter/base.rb @@ -40,7 +40,7 @@ def present(message, env) end if presenter - embeds = { env: env } + embeds = { env: } embeds[:version] = env[Grape::Env::API_VERSION] if env.key?(Grape::Env::API_VERSION) presented_message = presenter.represent(presented_message, embeds).serializable_hash end @@ -51,7 +51,7 @@ def present(message, env) def wrap_message(message) return message if message.is_a?(Hash) - { message: message } + { message: } end def format_structured_message(_structured_message) diff --git a/lib/grape/exceptions/incompatible_option_values.rb b/lib/grape/exceptions/incompatible_option_values.rb index aabe8d5eb..d58c0a20a 100644 --- a/lib/grape/exceptions/incompatible_option_values.rb +++ b/lib/grape/exceptions/incompatible_option_values.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class IncompatibleOptionValues < Base def initialize(option1, value1, option2, value2) - super(message: compose_message(:incompatible_option_values, option1: option1, value1: value1, option2: option2, value2: value2)) + super(message: compose_message(:incompatible_option_values, option1:, value1:, option2:, value2:)) end end end diff --git a/lib/grape/exceptions/invalid_accept_header.rb b/lib/grape/exceptions/invalid_accept_header.rb index fd98849c0..1972faa85 100644 --- a/lib/grape/exceptions/invalid_accept_header.rb +++ b/lib/grape/exceptions/invalid_accept_header.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class InvalidAcceptHeader < Base def initialize(message, headers) - super(message: compose_message(:invalid_accept_header, message: message), status: 406, headers: headers) + super(message: compose_message(:invalid_accept_header, message:), status: 406, headers:) end end end diff --git a/lib/grape/exceptions/invalid_formatter.rb b/lib/grape/exceptions/invalid_formatter.rb index 8c8a82f09..717ff9dd7 100644 --- a/lib/grape/exceptions/invalid_formatter.rb +++ b/lib/grape/exceptions/invalid_formatter.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class InvalidFormatter < Base def initialize(klass, to_format) - super(message: compose_message(:invalid_formatter, klass: klass, to_format: to_format)) + super(message: compose_message(:invalid_formatter, klass:, to_format:)) end end end diff --git a/lib/grape/exceptions/invalid_message_body.rb b/lib/grape/exceptions/invalid_message_body.rb index ac9c2efbf..77932c890 100644 --- a/lib/grape/exceptions/invalid_message_body.rb +++ b/lib/grape/exceptions/invalid_message_body.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class InvalidMessageBody < Base def initialize(body_format) - super(message: compose_message(:invalid_message_body, body_format: body_format), status: 400) + super(message: compose_message(:invalid_message_body, body_format:), status: 400) end end end diff --git a/lib/grape/exceptions/invalid_version_header.rb b/lib/grape/exceptions/invalid_version_header.rb index cb01ec3d1..1f37598d3 100644 --- a/lib/grape/exceptions/invalid_version_header.rb +++ b/lib/grape/exceptions/invalid_version_header.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class InvalidVersionHeader < Base def initialize(message, headers) - super(message: compose_message(:invalid_version_header, message: message), status: 406, headers: headers) + super(message: compose_message(:invalid_version_header, message:), status: 406, headers:) end end end diff --git a/lib/grape/exceptions/invalid_versioner_option.rb b/lib/grape/exceptions/invalid_versioner_option.rb index 9411370b0..49cfc929b 100644 --- a/lib/grape/exceptions/invalid_versioner_option.rb +++ b/lib/grape/exceptions/invalid_versioner_option.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class InvalidVersionerOption < Base def initialize(strategy) - super(message: compose_message(:invalid_versioner_option, strategy: strategy)) + super(message: compose_message(:invalid_versioner_option, strategy:)) end end end diff --git a/lib/grape/exceptions/method_not_allowed.rb b/lib/grape/exceptions/method_not_allowed.rb index 5777e4c29..0254a5157 100644 --- a/lib/grape/exceptions/method_not_allowed.rb +++ b/lib/grape/exceptions/method_not_allowed.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class MethodNotAllowed < Base def initialize(headers) - super(message: '405 Not Allowed', status: 405, headers: headers) + super(message: '405 Not Allowed', status: 405, headers:) end end end diff --git a/lib/grape/exceptions/missing_mime_type.rb b/lib/grape/exceptions/missing_mime_type.rb index 5bf43a1dc..dcddc11ca 100644 --- a/lib/grape/exceptions/missing_mime_type.rb +++ b/lib/grape/exceptions/missing_mime_type.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class MissingMimeType < Base def initialize(new_format) - super(message: compose_message(:missing_mime_type, new_format: new_format)) + super(message: compose_message(:missing_mime_type, new_format:)) end end end diff --git a/lib/grape/exceptions/unknown_auth_strategy.rb b/lib/grape/exceptions/unknown_auth_strategy.rb index 04689e2f8..0d28e94cc 100644 --- a/lib/grape/exceptions/unknown_auth_strategy.rb +++ b/lib/grape/exceptions/unknown_auth_strategy.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class UnknownAuthStrategy < Base def initialize(strategy:) - super(message: compose_message(:unknown_auth_strategy, strategy: strategy)) + super(message: compose_message(:unknown_auth_strategy, strategy:)) end end end diff --git a/lib/grape/exceptions/unknown_parameter.rb b/lib/grape/exceptions/unknown_parameter.rb index 0168ff39d..b521bd235 100644 --- a/lib/grape/exceptions/unknown_parameter.rb +++ b/lib/grape/exceptions/unknown_parameter.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class UnknownParameter < Base def initialize(param) - super(message: compose_message(:unknown_parameter, param: param)) + super(message: compose_message(:unknown_parameter, param:)) end end end diff --git a/lib/grape/exceptions/unknown_params_builder.rb b/lib/grape/exceptions/unknown_params_builder.rb index 449860998..e75836797 100644 --- a/lib/grape/exceptions/unknown_params_builder.rb +++ b/lib/grape/exceptions/unknown_params_builder.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class UnknownParamsBuilder < Base def initialize(params_builder_type) - super(message: compose_message(:unknown_params_builder, params_builder_type: params_builder_type)) + super(message: compose_message(:unknown_params_builder, params_builder_type:)) end end end diff --git a/lib/grape/exceptions/unknown_validator.rb b/lib/grape/exceptions/unknown_validator.rb index e856f2b36..fa187efaa 100644 --- a/lib/grape/exceptions/unknown_validator.rb +++ b/lib/grape/exceptions/unknown_validator.rb @@ -4,7 +4,7 @@ module Grape module Exceptions class UnknownValidator < Base def initialize(validator_type) - super(message: compose_message(:unknown_validator, validator_type: validator_type)) + super(message: compose_message(:unknown_validator, validator_type:)) end end end diff --git a/lib/grape/exceptions/validation.rb b/lib/grape/exceptions/validation.rb index 8599c94e7..2d68e9f57 100644 --- a/lib/grape/exceptions/validation.rb +++ b/lib/grape/exceptions/validation.rb @@ -15,7 +15,7 @@ def initialize(params:, message: nil, status: nil, headers: nil) message = translate_message(message) end - super(status: status, message: message, headers: headers) + super(status:, message:, headers:) end # Remove all the unnecessary stuff from Grape::Exceptions::Base like status diff --git a/lib/grape/exceptions/validation_errors.rb b/lib/grape/exceptions/validation_errors.rb index 0fbe70c83..3a23c4676 100644 --- a/lib/grape/exceptions/validation_errors.rb +++ b/lib/grape/exceptions/validation_errors.rb @@ -9,7 +9,7 @@ class ValidationErrors < Base def initialize(errors: [], headers: {}) @errors = errors.group_by(&:params) - super(message: full_messages.join(', '), status: 400, headers: headers) + super(message: full_messages.join(', '), status: 400, headers:) end def each diff --git a/lib/grape/middleware/error.rb b/lib/grape/middleware/error.rb index ef4c7db19..3403c88ec 100644 --- a/lib/grape/middleware/error.rb +++ b/lib/grape/middleware/error.rb @@ -38,8 +38,8 @@ def format_message(message, backtrace, original_exception = nil) throw :error, status: 406, message: "The requested format '#{format}' is not supported.", - backtrace: backtrace, - original_exception: original_exception + backtrace:, + original_exception: end def find_handler(klass) diff --git a/lib/grape/middleware/formatter.rb b/lib/grape/middleware/formatter.rb index 1f5e7cf40..fe616adbd 100644 --- a/lib/grape/middleware/formatter.rb +++ b/lib/grape/middleware/formatter.rb @@ -38,7 +38,7 @@ def build_formatted_response(status, headers, bodies) else # Allow content-type to be explicitly overwritten formatter = fetch_formatter(headers, options) - bodymap = ActiveSupport::Notifications.instrument('format_response.grape', formatter: formatter, env: env) do + bodymap = ActiveSupport::Notifications.instrument('format_response.grape', formatter:, env:) do bodies.collect { |body| formatter.call(body, env) } end Rack::Response.new(bodymap, status, headers) diff --git a/lib/grape/middleware/versioner/accept_version_header.rb b/lib/grape/middleware/versioner/accept_version_header.rb index 53bb39f83..eca0c6342 100644 --- a/lib/grape/middleware/versioner/accept_version_header.rb +++ b/lib/grape/middleware/versioner/accept_version_header.rb @@ -30,7 +30,7 @@ def before private def not_acceptable!(message) - throw :error, status: 406, headers: error_headers, message: message + throw :error, status: 406, headers: error_headers, message: end end end diff --git a/lib/grape/router/pattern.rb b/lib/grape/router/pattern.rb index 0bcfa9059..5e5c97d99 100644 --- a/lib/grape/router/pattern.rb +++ b/lib/grape/router/pattern.rb @@ -16,7 +16,7 @@ class Pattern def initialize(origin:, suffix:, anchor:, params:, format:, version:, requirements:) @origin = origin @path = PatternCache[[build_path_from_pattern(@origin, anchor), suffix]] - @pattern = Mustermann::Grape.new(@path, uri_decode: true, params: params, capture: extract_capture(format, version, requirements)) + @pattern = Mustermann::Grape.new(@path, uri_decode: true, params:, capture: extract_capture(format, version, requirements)) @to_regexp = @pattern.to_regexp end diff --git a/lib/grape/util/api_description.rb b/lib/grape/util/api_description.rb index e3daa54ed..e347762b4 100644 --- a/lib/grape/util/api_description.rb +++ b/lib/grape/util/api_description.rb @@ -25,7 +25,7 @@ class ApiDescription def initialize(description, endpoint_configuration, &) @endpoint_configuration = endpoint_configuration - @attributes = { description: description } + @attributes = { description: } instance_eval(&) end diff --git a/lib/grape/util/media_type.rb b/lib/grape/util/media_type.rb index ea4c2c3d9..2faddb47a 100644 --- a/lib/grape/util/media_type.rb +++ b/lib/grape/util/media_type.rb @@ -47,7 +47,7 @@ def parse(media_type) type, subtype = media_type.split('/', 2) return if type.blank? || subtype.blank? - new(type: type, subtype: subtype) + new(type:, subtype:) end def match?(media_type) diff --git a/lib/grape/validations/params_scope.rb b/lib/grape/validations/params_scope.rb index d50357d8a..335cdad6c 100644 --- a/lib/grape/validations/params_scope.rb +++ b/lib/grape/validations/params_scope.rb @@ -275,10 +275,10 @@ def new_scope(element, type:, as:, optional: false, &) self.class.new( api: @api, - element: element, + element:, element_renamed: as, parent: self, - optional: optional, + optional:, type: type || Array, group: @group, & @@ -306,7 +306,7 @@ def new_lateral_scope(dependent_on:, &) # @param group [Hash] common options to merge into each parameter in the scope # @yield parameter scope def new_group_scope(group, &) - self.class.new(api: @api, parent: self, group: group, &) + self.class.new(api: @api, parent: self, group:, &) end # Pushes declared params to parent or settings, then clears @declared_params. diff --git a/lib/grape/validations/validators/base.rb b/lib/grape/validations/validators/base.rb index ac1249108..33c8e322c 100644 --- a/lib/grape/validations/validators/base.rb +++ b/lib/grape/validations/validators/base.rb @@ -117,7 +117,7 @@ def validate_param!(attr_name, params) def validation_error!(attr_name_or_params, message = @exception_message) params = attr_name_or_params.is_a?(Array) ? attr_name_or_params : @scope.full_name(attr_name_or_params) - raise Grape::Exceptions::Validation.new(params: params, message: message) + raise Grape::Exceptions::Validation.new(params:, message:) end def hash_like?(obj) diff --git a/spec/grape/api/documentation_spec.rb b/spec/grape/api/documentation_spec.rb index 27ec7cc53..baa088568 100644 --- a/spec/grape/api/documentation_spec.rb +++ b/spec/grape/api/documentation_spec.rb @@ -21,7 +21,7 @@ documentation = { example: 'Joe' } subject.params do - requires 'first_name', documentation: documentation + requires 'first_name', documentation: end subject.get '/' diff --git a/spec/grape/api/inherited_helpers_spec.rb b/spec/grape/api/inherited_helpers_spec.rb index 49597bc5b..7b3cab7f8 100644 --- a/spec/grape/api/inherited_helpers_spec.rb +++ b/spec/grape/api/inherited_helpers_spec.rb @@ -57,7 +57,7 @@ def app context 'given expected params' do it 'inherits helpers from a superclass' do - get '/resource', id: id, user: user + get('/resource', id:, user:) expect(last_response.body).to eq("#{user}: #{id}") end end @@ -77,7 +77,7 @@ def app context 'given expected params' do it 'overrides helpers from a superclass' do - get '/resource', id: id, user: user + get('/resource', id:, user:) expect(last_response.body).to eq("#{user} with id: #{id}") end end @@ -97,7 +97,7 @@ def app context 'given expected params' do it 'inherits helpers from a superclass' do - get '/resource', id: id, user: user + get('/resource', id:, user:) expect(last_response.body).to eq("#{user}: #{id}") end end diff --git a/spec/grape/api_remount_spec.rb b/spec/grape/api_remount_spec.rb index ed5326b82..464478190 100644 --- a/spec/grape/api_remount_spec.rb +++ b/spec/grape/api_remount_spec.rb @@ -210,7 +210,7 @@ it 'mounts the API and obtains the description and headers definition' do root_api.mount a_remounted_api, with: { description: endpoint_description, - headers: headers, + headers:, endpoint: api_endpoint, response: api_response } diff --git a/spec/grape/api_spec.rb b/spec/grape/api_spec.rb index 1fb699dbf..a2f374003 100644 --- a/spec/grape/api_spec.rb +++ b/spec/grape/api_spec.rb @@ -4281,7 +4281,7 @@ def before [true, false].each do |anchor| it "anchor=#{anchor}" do - subject.route :any, '*path', anchor: anchor do + subject.route(:any, '*path', anchor:) do error!("Unrecognized request path: #{params[:path]} - #{env[Rack::PATH_INFO]}#{env[Rack::SCRIPT_NAME]}", 404) end get '/v1/hello' diff --git a/spec/grape/dsl/inside_route_spec.rb b/spec/grape/dsl/inside_route_spec.rb index 7d48e5ece..feb610b65 100644 --- a/spec/grape/dsl/inside_route_spec.rb +++ b/spec/grape/dsl/inside_route_spec.rb @@ -100,7 +100,7 @@ def header(key = nil, val = nil) describe '#status' do %w[GET PUT OPTIONS].each do |method| it 'defaults to 200 on GET' do - request = Grape::Request.new(Rack::MockRequest.env_for('/', method: method)) + request = Grape::Request.new(Rack::MockRequest.env_for('/', method:)) expect(subject).to receive(:request).and_return(request).twice expect(subject.status).to eq 200 end diff --git a/spec/grape/endpoint/declared_spec.rb b/spec/grape/endpoint/declared_spec.rb index 0193c0f92..cc31bc502 100644 --- a/spec/grape/endpoint/declared_spec.rb +++ b/spec/grape/endpoint/declared_spec.rb @@ -439,7 +439,7 @@ route_param :y do get do { - params: params, + params:, declared_params: declared(params) } end @@ -492,7 +492,7 @@ namespace 'foo' do get do { - params: params, + params:, declared_params: declared(params), declared_params_no_parent: declared(params, include_parent_namespaces: false) } @@ -686,7 +686,7 @@ before = params.to_h declared(params, include_missing: false) after = params.to_h - { before: before, after: after } + { before:, after: } end end diff --git a/spec/grape/exceptions/base_spec.rb b/spec/grape/exceptions/base_spec.rb index 16b07ac43..b9b8bc82d 100644 --- a/spec/grape/exceptions/base_spec.rb +++ b/spec/grape/exceptions/base_spec.rb @@ -2,7 +2,7 @@ describe Grape::Exceptions::Base do describe '#to_s' do - subject { described_class.new(message: message).to_s } + subject { described_class.new(message:).to_s } let(:message) { 'a_message' } @@ -10,7 +10,7 @@ end describe '#message' do - subject { described_class.new(message: message).message } + subject { described_class.new(message:).message } let(:message) { 'a_message' } diff --git a/spec/grape/exceptions/validation_errors_spec.rb b/spec/grape/exceptions/validation_errors_spec.rb index 4bba43d65..c75930af9 100644 --- a/spec/grape/exceptions/validation_errors_spec.rb +++ b/spec/grape/exceptions/validation_errors_spec.rb @@ -6,7 +6,7 @@ context 'initialize' do subject do - described_class.new(errors: [validation_error], headers: headers) + described_class.new(errors: [validation_error], headers:) end let(:headers) do diff --git a/spec/grape/middleware/auth/strategies_spec.rb b/spec/grape/middleware/auth/strategies_spec.rb index 38bb29fb3..8e42776ae 100644 --- a/spec/grape/middleware/auth/strategies_spec.rb +++ b/spec/grape/middleware/auth/strategies_spec.rb @@ -6,7 +6,7 @@ proc = ->(u, p) { u && p && u == p } Rack::Builder.app do use Grape::Middleware::Error - use(Grape::Middleware::Auth::Base, type: :http_basic, proc: proc) + use(Grape::Middleware::Auth::Base, type: :http_basic, proc:) run ->(_env) { [200, {}, ['Hello there.']] } end end diff --git a/spec/grape/middleware/exception_spec.rb b/spec/grape/middleware/exception_spec.rb index 6d7712ea9..6a34bfe4a 100644 --- a/spec/grape/middleware/exception_spec.rb +++ b/spec/grape/middleware/exception_spec.rb @@ -35,7 +35,7 @@ def call(_env) Class.new do class << self def error!(message, status) - throw :error, message: { error: message, detail: 'missing widget' }, status: status + throw :error, message: { error: message, detail: 'missing widget' }, status: end def call(_env) @@ -49,7 +49,7 @@ def call(_env) Class.new do class << self def error!(message, status) - throw :error, message: message, status: status + throw :error, message:, status: end def call(_env) diff --git a/spec/grape/middleware/versioner/path_spec.rb b/spec/grape/middleware/versioner/path_spec.rb index 79aff5376..8aec7d748 100644 --- a/spec/grape/middleware/versioner/path_spec.rb +++ b/spec/grape/middleware/versioner/path_spec.rb @@ -32,7 +32,7 @@ [%w[v1 v2], %i[v1 v2], [:v1, 'v2'], ['v1', :v2]].each do |versions| context "with specified versions as #{versions}" do - let(:options) { { versions: versions } } + let(:options) { { versions: } } it 'throws an error if a non-allowed version is specified' do expect(catch(:error) { subject.call(Rack::PATH_INFO => '/v3/awesome') }[:status]).to eq(404) diff --git a/spec/grape/request_spec.rb b/spec/grape/request_spec.rb index a0a753e31..19675178f 100644 --- a/spec/grape/request_spec.rb +++ b/spec/grape/request_spec.rb @@ -5,8 +5,8 @@ let(:default_params) { {} } let(:default_options) do { - method: method, - params: params + method:, + params: } end let(:default_env) do diff --git a/spec/grape/router/greedy_route_spec.rb b/spec/grape/router/greedy_route_spec.rb index 39c82c87b..dba8966f1 100644 --- a/spec/grape/router/greedy_route_spec.rb +++ b/spec/grape/router/greedy_route_spec.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true RSpec.describe Grape::Router::GreedyRoute do - let(:instance) { described_class.new(pattern, endpoint: endpoint, allow_header: allow_header) } + let(:instance) { described_class.new(pattern, endpoint:, allow_header:) } let(:pattern) { :pattern } let(:endpoint) { instance_double(Grape::Endpoint) } let(:allow_header) { false } diff --git a/spec/grape/util/media_type_spec.rb b/spec/grape/util/media_type_spec.rb index 2905c3f9e..09e328513 100644 --- a/spec/grape/util/media_type_spec.rb +++ b/spec/grape/util/media_type_spec.rb @@ -2,7 +2,7 @@ RSpec.describe Grape::Util::MediaType do shared_examples 'MediaType' do - it { is_expected.to eq(described_class.new(type: type, subtype: subtype)) } + it { is_expected.to eq(described_class.new(type:, subtype:)) } end describe '.parse' do @@ -91,13 +91,13 @@ it 'calls Rack::Utils.best_q_match' do allow(Rack::Utils).to receive(:best_q_match).and_call_original - expect(media_type).to eq(described_class.new(type: type, subtype: subtype)) + expect(media_type).to eq(described_class.new(type:, subtype:)) end end end describe '.==' do - subject { described_class.new(type: type, subtype: subtype) } + subject { described_class.new(type:, subtype:) } let(:type) { 'application' } let(:subtype) { 'vnd.test-v1+json' } @@ -108,11 +108,11 @@ end describe '.hash' do - subject { Set.new([described_class.new(type: type, subtype: subtype)]) } + subject { Set.new([described_class.new(type:, subtype:)]) } let(:type) { 'text' } let(:subtype) { 'html' } - it { is_expected.to include(described_class.new(type: type, subtype: subtype)) } + it { is_expected.to include(described_class.new(type:, subtype:)) } end end diff --git a/spec/grape/validations/params_scope_spec.rb b/spec/grape/validations/params_scope_spec.rb index 223fa3b13..371184f64 100644 --- a/spec/grape/validations/params_scope_spec.rb +++ b/spec/grape/validations/params_scope_spec.rb @@ -865,7 +865,7 @@ def initialize(value) optional :b end end - subject.get("/evaluate_given_#{evaluate_given}") { declared(params, evaluate_given: evaluate_given).to_json } + subject.get("/evaluate_given_#{evaluate_given}") { declared(params, evaluate_given:).to_json } end end @@ -898,7 +898,7 @@ def initialize(value) optional :f end end - subject.get("/evaluate_given_#{evaluate_given}") { declared(params, evaluate_given: evaluate_given).to_json } + subject.get("/evaluate_given_#{evaluate_given}") { declared(params, evaluate_given:).to_json } end end @@ -947,7 +947,7 @@ def initialize(value) end end end - subject.get("/evaluate_given_#{evaluate_given}") { declared(params, evaluate_given: evaluate_given).to_json } + subject.get("/evaluate_given_#{evaluate_given}") { declared(params, evaluate_given:).to_json } end end @@ -992,7 +992,7 @@ def initialize(value) end end subject.post("/evaluate_given_#{evaluate_given}") do - declared(params, evaluate_given: evaluate_given).to_json + declared(params, evaluate_given:).to_json end end end @@ -1021,7 +1021,7 @@ def initialize(value) end end subject.post("/evaluate_given_#{evaluate_given}") do - declared(params, evaluate_given: evaluate_given).to_json + declared(params, evaluate_given:).to_json end end end @@ -1064,7 +1064,7 @@ def initialize(value) end end subject.post("/evaluate_given_#{evaluate_given}") do - declared(params, evaluate_given: evaluate_given).to_json + declared(params, evaluate_given:).to_json end end end @@ -1113,7 +1113,7 @@ def initialize(value) end end subject.post("/evaluate_given_#{evaluate_given}") do - declared(params, evaluate_given: evaluate_given).to_json + declared(params, evaluate_given:).to_json end end end diff --git a/spec/grape/validations/validators/coerce_validator_spec.rb b/spec/grape/validations/validators/coerce_validator_spec.rb index a9fae7280..c89ef6a40 100644 --- a/spec/grape/validations/validators/coerce_validator_spec.rb +++ b/spec/grape/validations/validators/coerce_validator_spec.rb @@ -263,7 +263,7 @@ def self.parse(_val) type = custom_type subject.params do - requires :name, type: type + requires :name, type: end subject.get '/whatever' do params[:name].class @@ -398,7 +398,7 @@ def self.parse(_val) params[:file][:filename] end - post '/upload', file: file + post('/upload', file:) expect(last_response).to be_created expect(last_response.body).to eq(filename) @@ -415,7 +415,7 @@ def self.parse(_val) params[:file][:filename] end - post '/upload', file: file + post('/upload', file:) expect(last_response).to be_created expect(last_response.body).to eq(filename) @@ -462,7 +462,7 @@ def self.parse(_val) Grape::Validations::Types::PRIMITIVES.each do |type| it 'respects the nil value' do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/nil_value' do params[:param].class @@ -479,7 +479,7 @@ def self.parse(_val) Grape::Validations::Types::STRUCTURES.each do |type| it 'respects the nil value' do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/nil_value' do params[:param].class @@ -496,7 +496,7 @@ def self.parse(_val) Grape::Validations::Types::SPECIAL.each_key do |type| it 'respects the nil value' do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/nil_value' do params[:param].class @@ -515,7 +515,7 @@ def self.parse(_val) ].each do |type| it 'respects the nil value' do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/nil_value' do params[:param].class @@ -535,7 +535,7 @@ def self.parse(_val) (Grape::Validations::Types::PRIMITIVES - [String]).each do |type| it "is coerced to nil for type #{type}" do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/empty_string' do params[:param].class @@ -565,7 +565,7 @@ def self.parse(_val) (Grape::Validations::Types::STRUCTURES - [Hash]).each do |type| it "is coerced to nil for type #{type}" do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/empty_string' do params[:param].class @@ -582,7 +582,7 @@ def self.parse(_val) (Grape::Validations::Types::SPECIAL.keys - [File, Rack::Multipart::UploadedFile]).each do |type| it "is coerced to nil for type #{type}" do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/empty_string' do params[:param].class @@ -601,7 +601,7 @@ def self.parse(_val) ].each do |type| it "is coerced to nil for type #{type}" do subject.params do - requires :param, type: type + requires :param, type: end subject.get '/empty_string' do params[:param].class diff --git a/spec/grape/validations/validators/default_validator_spec.rb b/spec/grape/validations/validators/default_validator_spec.rb index 92e9066b7..831f15b28 100644 --- a/spec/grape/validations/validators/default_validator_spec.rb +++ b/spec/grape/validations/validators/default_validator_spec.rb @@ -417,7 +417,7 @@ def app ].each do |type, default| it 'respects the default value' do subject.params do - optional :param, type: type, default: default + optional :param, type:, default: end subject.get '/default_value' do params[:param] @@ -442,7 +442,7 @@ def app ].each do |type, default| it 'respects the default value' do subject.params do - optional :param, type: type, default: default + optional :param, type:, default: end subject.get '/default_value' do params[:param] @@ -468,7 +468,7 @@ def app ].each do |type, default| it 'respects the default value' do subject.params do - optional :param, type: type, default: default + optional :param, type:, default: end subject.get '/default_value' do params[:param] @@ -490,7 +490,7 @@ def app ].each do |type, default| it 'respects the default value' do subject.params do - optional :param, type: type, default: default + optional :param, type:, default: end subject.get '/default_value' do params[:param] diff --git a/spec/grape/validations_spec.rb b/spec/grape/validations_spec.rb index 23aa17e3f..63c1e4598 100644 --- a/spec/grape/validations_spec.rb +++ b/spec/grape/validations_spec.rb @@ -1409,7 +1409,7 @@ def validate_param!(attr_name, params) def validate_param!(attr_name, params) return if params[attr_name] == @option[:text] - raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message: message) + raise Grape::Exceptions::Validation.new(params: [@scope.full_name(attr_name)], message:) end end end diff --git a/spec/integration/hashie/hashie_spec.rb b/spec/integration/hashie/hashie_spec.rb index 96d3388f9..c4d373e73 100644 --- a/spec/integration/hashie/hashie_spec.rb +++ b/spec/integration/hashie/hashie_spec.rb @@ -112,8 +112,8 @@ let(:default_params) { {} } let(:default_options) do { - method: method, - params: params + method:, + params: } end let(:default_env) do diff --git a/spec/support/versioned_helpers.rb b/spec/support/versioned_helpers.rb index ce682e0d7..26e5a67c5 100644 --- a/spec/support/versioned_helpers.rb +++ b/spec/support/versioned_helpers.rb @@ -38,7 +38,7 @@ def versioned_headers(options) end def versioned_get(path, version_name, version_options) - path = versioned_path(version_options.merge(version: version_name, path: path)) + path = versioned_path(version_options.merge(version: version_name, path:)) headers = versioned_headers(version_options.merge(version: version_name)) params = {} params = { version_options[:parameter] => version_name } if version_options[:using] == :param