Skip to content

Conversation

@ericproulx
Copy link
Contributor

This PR replaces options = {} to modern **options with explicit optional parameters requirements and type.

@ericproulx ericproulx force-pushed the namespace_route_param_explicit_kwargs branch from b9c8f54 to 035f3ef Compare December 20, 2025 20:21
@ericproulx ericproulx requested a review from dblock December 20, 2025 20:36
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixup spelling in UPGRADING + some questions/rebase please?

param.to_sym => options[:requirements]
} if options[:requirements].is_a?(Regexp)
def route_param(param, requirements: nil, type: nil, **options, &block)
requirements = { param.to_sym => requirements } if requirements.is_a?(Regexp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
requirements = { param.to_sym => requirements } if requirements.is_a?(Regexp)
requirements = { param.to_sym => requirements } if requirements&.is_a?(Regexp)

Nit, but that avoids calling is_a?(nil)?


#### Explicit kwargs for `namespace` and `route_param`

`namespace` and `route_param` are now now defined with a `**options` instead of `options = {}`. In addtion, `requirements` in explicitely defined so its not in `options` anymore. You can still call `requirements` like before but `options[:requirements]` will be empty. For `route_param`, `type` is also an explicit parameter so it's not in `options` anymore. See [#2647](https://github.com/ruby-grape/grape/pull/2647) for more information.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`namespace` and `route_param` are now now defined with a `**options` instead of `options = {}`. In addtion, `requirements` in explicitely defined so its not in `options` anymore. You can still call `requirements` like before but `options[:requirements]` will be empty. For `route_param`, `type` is also an explicit parameter so it's not in `options` anymore. See [#2647](https://github.com/ruby-grape/grape/pull/2647) for more information.
The `API#namespace` and `route_param` methods are now defined with `**options` instead of `options = {}`. In addtion, `requirements` in explicitly defined so it's not in `options` anymore. You can still call `requirements` like before but `options[:requirements]` will be empty. For `route_param`, `type` is also an explicit parameter so it's not in `options` anymore. See [#2647](https://github.com/ruby-grape/grape/pull/2647) for more information.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this part of an API change/breaking change?
Does this need a before/after with an example of how to call it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants