Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
* [#2684](https://github.com/ruby-grape/grape/pull/2684): Readability refactors: case/when, guard clauses, small cleanups - [@ericproulx](https://github.com/ericproulx).
* [#2687](https://github.com/ruby-grape/grape/pull/2687): Skip backtrace capture on internal validation exceptions - [@ericproulx](https://github.com/ericproulx).
* [#2688](https://github.com/ruby-grape/grape/pull/2688): Consolidate user-registered rescue handler lookup into `Middleware::Error#registered_rescue_handler` backed by a shared `rescue_handler_from` primitive - [@ericproulx](https://github.com/ericproulx).
* [#2689](https://github.com/ruby-grape/grape/pull/2689): Avoid empty-hash merges on request hot paths - [@ericproulx](https://github.com/ericproulx).
* Your contribution here.

#### Fixes
Expand Down
4 changes: 4 additions & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Upgrading Grape

### Upgrading to >= 3.3

#### `Grape::Request#grape_routing_args` has been removed

`grape_routing_args` was previously public to support third-party `params_builder` extensions, which have since been removed. With no remaining callers, the method has been removed. If you were calling it externally, read `env[Grape::Env::GRAPE_ROUTING_ARGS]` directly.

#### `endpoint_run_filters.grape` notification no longer fired for empty filter lists

`ActiveSupport::Notifications` subscribers listening to `endpoint_run_filters.grape` will no longer receive an event when the filter list for a given phase (`:before`, `:before_validation`, `:after_validation`, `:after`, `:finally`) is empty. Previously every phase emitted an event on every request regardless of whether any filters were registered. If you relied on these events to infer per-phase timing, subscribe to `endpoint_run.grape` (which always fires once per request) or register a no-op filter to keep the phase instrumented.
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/dsl/entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def present(*args, root: nil, with: nil, **options)
representation = { root => representation } if root

if key
representation = (body || {}).merge(key => representation)
representation = body&.merge(key => representation) || { key => representation }
elsif entity_class.present? && body
raise ArgumentError, "Representation of type #{representation.class} cannot be merged." unless representation.respond_to?(:merge)

Expand Down
10 changes: 3 additions & 7 deletions lib/grape/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,16 +156,12 @@ def cookies
@cookies ||= Grape::Cookies.new(-> { rack_cookies })
end

# needs to be public until extensions param_builder are removed
def grape_routing_args
# preserve version from query string parameters
env[Grape::Env::GRAPE_ROUTING_ARGS]&.except(:version, :route_info) || {}
end

private

def make_params
@params_builder.call(rack_params).deep_merge!(grape_routing_args)
params = @params_builder.call(rack_params)
routing_args = env[Grape::Env::GRAPE_ROUTING_ARGS]&.except(:version, :route_info)&.presence
routing_args ? params.deep_merge!(routing_args) : params
rescue *Grape::RACK_ERRORS
raise Grape::Exceptions::RequestError
end
Expand Down
3 changes: 1 addition & 2 deletions lib/grape/router.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ def transaction(input, method, env)
def process_route(route, input, env, include_allow_header: false)
args = env[Grape::Env::GRAPE_ROUTING_ARGS] || { route_info: route }
route_params = route.params(input)
routing_args = args.merge(route_params || {})
env[Grape::Env::GRAPE_ROUTING_ARGS] = routing_args
env[Grape::Env::GRAPE_ROUTING_ARGS] = route_params.blank? ? args : args.merge(route_params)
env[Grape::Env::GRAPE_ALLOWED_METHODS] = route.allow_header if include_allow_header
route.call(env)
end
Expand Down
Loading