Skip to content

Commit 6dc01a7

Browse files
authored
Merge pull request #2605 from ruby-grape/add_rack_3_2_gemfile
Add Rack 3.2 Support
2 parents d2d7798 + c0a3f75 commit 6dc01a7

File tree

17 files changed

+67
-122
lines changed

17 files changed

+67
-122
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fail-fast: false
2525
matrix:
2626
ruby: ['3.0', '3.1', '3.2', '3.3', '3.4']
27-
gemfile: [Gemfile, gemfiles/rack_2_0.gemfile, gemfiles/rack_3_0.gemfile, gemfiles/rack_3_1.gemfile, gemfiles/rails_7_0.gemfile, gemfiles/rails_7_1.gemfile, gemfiles/rails_7_2.gemfile, gemfiles/rails_8_0.gemfile]
27+
gemfile: [Gemfile, gemfiles/rack_2_0.gemfile, gemfiles/rack_3_0.gemfile, gemfiles/rack_3_1.gemfile, gemfiles/rack_3_2.gemfile, gemfiles/rails_7_0.gemfile, gemfiles/rails_7_1.gemfile, gemfiles/rails_7_2.gemfile, gemfiles/rails_8_0.gemfile]
2828
specs: ['spec --exclude-pattern=spec/integration/**/*_spec.rb']
2929
include:
3030
- ruby: '3.3'

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Style/Send:
3535
Enabled: true
3636

3737
Metrics/AbcSize:
38-
Max: 45
38+
Max: 50
3939

4040
Metrics/BlockLength:
4141
Max: 30

.simplecov

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ if ENV['GITHUB_USER'] # only when running CI
1111
end
1212

1313
SimpleCov.start do
14+
enable_coverage :branch
1415
add_filter '/spec/'
1516
end

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
* [#2599](https://github.com/ruby-grape/grape/pull/2599): Simplify settings DSL get_or_set method and optimize logger implementation - [@ericproulx](https://github.com/ericproulx).
1616
* [#2600](https://github.com/ruby-grape/grape/pull/2600): Refactor versioner middleware: simplify base class and improve consistency - [@ericproulx](https://github.com/ericproulx).
1717
* [#2601](https://github.com/ruby-grape/grape/pull/2601): Refactor route_setting internal usage to use inheritable_setting.route for improved consistency and performance - [@ericproulx](https://github.com/ericproulx).
18+
* [#2602](https://github.com/ruby-grape/grape/pull/2602): Remove `namespace_reverse_stackable` from public DSL interface and use direct inheritable_setting access - [@ericproulx](https://github.com/ericproulx).
19+
* [#2603](https://github.com/ruby-grape/grape/pull/2603): Remove `namespace_stackable_with_hash` from public interface and move to internal InheritableSetting - [@ericproulx](https://github.com/ericproulx).
20+
* [#2604](https://github.com/ruby-grape/grape/pull/2604): Enable branch coverage - [@ericproulx](https://github.com/ericproulx).
21+
* [#2605](https://github.com/ruby-grape/grape/pull/2605): Add Rack 3.2 support with new gemfile and CI integration - [@ericproulx](https://github.com/ericproulx).
1822
* Your contribution here.
1923

2024
#### Fixes

gemfiles/rack_3_2.gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
eval_gemfile '../Gemfile'
4+
5+
gem 'rack', '~> 3.2'

lib/grape/dsl/desc.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def desc(description, options = {}, &config_block)
5757
else
5858
options.merge(description: description)
5959
end
60-
namespace_setting :description, settings
60+
inheritable_setting.namespace[:description] = settings
6161
inheritable_setting.route[:description] = settings
6262
end
6363
end

lib/grape/dsl/inside_route.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,22 +389,22 @@ def route
389389
# @return [Class] the located Entity class, or nil if none is found
390390
def entity_class_for_obj(object, options)
391391
entity_class = options.delete(:with)
392-
393-
if entity_class.nil?
394-
# entity class not explicitly defined, auto-detect from relation#klass or first object in the collection
395-
object_class = if object.respond_to?(:klass)
396-
object.klass
397-
else
398-
object.respond_to?(:first) ? object.first.class : object.class
399-
end
400-
401-
object_class.ancestors.each do |potential|
402-
entity_class ||= (namespace_stackable_with_hash(:representations) || {})[potential]
403-
end
404-
405-
entity_class ||= object_class.const_get(:Entity) if object_class.const_defined?(:Entity) && object_class.const_get(:Entity).respond_to?(:represent)
392+
return entity_class if entity_class
393+
394+
# entity class not explicitly defined, auto-detect from relation#klass or first object in the collection
395+
object_class = if object.respond_to?(:klass)
396+
object.klass
397+
else
398+
object.respond_to?(:first) ? object.first.class : object.class
399+
end
400+
401+
representations = inheritable_setting.namespace_stackable_with_hash(:representations)
402+
if representations
403+
potential = object_class.ancestors.detect { |potential| representations.key?(potential) }
404+
entity_class = representations[potential] if potential
406405
end
407406

407+
entity_class = object_class.const_get(:Entity) if !entity_class && object_class.const_defined?(:Entity) && object_class.const_get(:Entity).respond_to?(:represent)
408408
entity_class
409409
end
410410

lib/grape/dsl/parameters.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def build_with(build_with)
5454
# end
5555
# end
5656
def use(*names)
57-
named_params = @api.namespace_stackable_with_hash(:named_params) || {}
57+
named_params = @api.inheritable_setting.namespace_stackable_with_hash(:named_params) || {}
5858
options = names.extract_options!
5959
names.each do |name|
6060
params_block = named_params.fetch(name) do

lib/grape/dsl/request_response.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def content_type(key, val)
6060

6161
# All available content types.
6262
def content_types
63-
c_types = namespace_stackable_with_hash(:content_types)
63+
c_types = inheritable_setting.namespace_stackable_with_hash(:content_types)
6464
Grape::ContentTypes.content_types_for c_types
6565
end
6666

@@ -117,7 +117,7 @@ def rescue_from(*args, &block)
117117
:base_only_rescue_handlers
118118
end
119119

120-
namespace_reverse_stackable(handler_type, args.to_h { |arg| [arg, handler] })
120+
inheritable_setting.namespace_reverse_stackable[handler_type] = args.to_h { |arg| [arg, handler] }
121121
end
122122

123123
namespace_stackable(:rescue_options, options)

lib/grape/dsl/routing.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,17 @@ def mount(mounts, *opts)
142142
# end
143143
def route(methods, paths = ['/'], route_options = {}, &block)
144144
method = methods == :any ? '*' : methods
145-
description = inheritable_setting.route[:description] || {}
145+
endpoint_params = inheritable_setting.namespace_stackable_with_hash(:params) || {}
146+
endpoint_description = inheritable_setting.route[:description]
147+
all_route_options = { params: endpoint_params }
148+
all_route_options.deep_merge!(endpoint_description) if endpoint_description
149+
all_route_options.deep_merge!(route_options) if route_options&.any?
150+
146151
endpoint_options = {
147152
method: method,
148153
path: paths,
149154
for: self,
150-
route_options: {
151-
params: namespace_stackable_with_hash(:params) || {}
152-
}.deep_merge(description).deep_merge(route_options || {})
155+
route_options: all_route_options
153156
}
154157

155158
new_endpoint = Grape::Endpoint.new(inheritable_setting, endpoint_options, &block)

0 commit comments

Comments
 (0)