grape 2.1.0 → 2.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ea97a4725e49023d0d321920359d449d1a97ac1ea796bf8393f680d512799c7
4
- data.tar.gz: 2f36ea240c2f987ec11479522a6a4f3113f3fb296903baa749305ba60e07ad44
3
+ metadata.gz: 024e352cc91ca60c4f0750b852ce4fba0dc574b33d647ef10958b4db12fc7090
4
+ data.tar.gz: d9fb3be3da671011a1bed81d5f986a1688d411903bcf550c9d6ea83c7dcb6e0f
5
5
  SHA512:
6
- metadata.gz: 9b09628eb40cf9fe5f08e01b3391d3a7abca14b24c8bdda9fb6b52d326c97c2edc7ceb05ba8a27826d6f6d902867d5cad1e031884a466b59677e893df81b52e1
7
- data.tar.gz: e1c916b0be5480c0f6cff795eefde716f6056a3f6cc28eb97235cb3c79b503e0028b69286447fb47d3850936a411863166bb8f09dc1de4f21a56b48b439b2572
6
+ metadata.gz: 6172f2a8d7567edcbebb7289d5e41bed65f66ffa9309dd37b03b57cf199bc84945cdfd241df84e6a92ecf28f9099b18b9fe08516470b38721cb256fce5de8a34
7
+ data.tar.gz: d5ce8b9292bc9e596a955ac0c748cb2c278daf68246192556a1ee91e726026bdced1586ea4b73818727ff3fd2b0f32df57f3674d7a5f585703cd91c7630f5b71
data/CHANGELOG.md CHANGED
@@ -1,3 +1,22 @@
1
+ ### 2.1.2 (2024-06-28)
2
+
3
+ #### Fixes
4
+
5
+ * [#2459](https://github.com/ruby-grape/grape/pull/2459): Autocorrect cops - [@ericproulx](https://github.com/ericproulx).
6
+ * [#3458](https://github.com/ruby-grape/grape/pull/2458): Remove unused Grape::Util::Accept::Header - [@ericproulx](https://github.com/ericproulx).
7
+ * [#2463](https://github.com/ruby-grape/grape/pull/2463): Fix error message indices - [@ericproulx](https://github.com/ericproulx).
8
+
9
+ ### 2.1.1 (2024-06-22)
10
+
11
+ #### Features
12
+
13
+ * [#2450](https://github.com/ruby-grape/grape/pull/2450): Update RuboCop to 1.64.1 - [@ericproulx](https://github.com/ericproulx).
14
+
15
+ #### Fixes
16
+
17
+ * [#2453](https://github.com/ruby-grape/grape/pull/2453): Fix context in rescue_from - [@ericproulx](https://github.com/ericproulx).
18
+ * [#2455](https://github.com/ruby-grape/grape/pull/2455): Fix default response headers to work with Rack 3 - [@ericproulx](https://github.com/ericproulx).
19
+
1
20
  ### 2.1.0 (2024/06/15)
2
21
 
3
22
  #### Features
data/README.md CHANGED
@@ -157,7 +157,7 @@ Grape is a REST-like API framework for Ruby. It's designed to run on Rack or com
157
157
 
158
158
  ## Stable Release
159
159
 
160
- You're reading the documentation for the stable release of Grape, **2.1.0**.
160
+ You're reading the documentation for the stable release of Grape, **2.1.2**.
161
161
  Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
162
162
 
163
163
  ## Project Resources
@@ -46,7 +46,7 @@ module Grape
46
46
  # Parses the API's definition and compiles it into an instance of
47
47
  # Grape::API.
48
48
  def compile
49
- @instance ||= new
49
+ @instance ||= new # rubocop:disable Naming/MemoizedInstanceVariableName
50
50
  end
51
51
 
52
52
  # Wipe the compiled API so we can recompile after changes were made.
data/lib/grape/api.rb CHANGED
@@ -32,7 +32,7 @@ module Grape
32
32
  def inherited(api)
33
33
  super
34
34
 
35
- api.initial_setup(Grape::API == self ? Grape::API::Instance : @base_instance)
35
+ api.initial_setup(self == Grape::API ? Grape::API::Instance : @base_instance)
36
36
  api.override_all_methods!
37
37
  end
38
38
 
@@ -108,7 +108,7 @@ module Grape
108
108
  end
109
109
 
110
110
  def respond_to?(method, include_private = false)
111
- super(method, include_private) || base_instance.respond_to?(method, include_private)
111
+ super || base_instance.respond_to?(method, include_private)
112
112
  end
113
113
 
114
114
  def respond_to_missing?(method, include_private = false)
@@ -461,6 +461,10 @@ module Grape
461
461
  def http_version
462
462
  env['HTTP_VERSION'] || env[Rack::SERVER_PROTOCOL]
463
463
  end
464
+
465
+ def context
466
+ self
467
+ end
464
468
  end
465
469
  end
466
470
  end
@@ -231,7 +231,7 @@ module Grape
231
231
 
232
232
  alias group requires
233
233
 
234
- class EmptyOptionalValue; end
234
+ class EmptyOptionalValue; end # rubocop:disable Lint/EmptyClass
235
235
 
236
236
  def map_params(params, element, is_array = false)
237
237
  if params.is_a?(Array)
@@ -231,8 +231,8 @@ module Grape
231
231
  options[:app].endpoints if options[:app].respond_to?(:endpoints)
232
232
  end
233
233
 
234
- def equals?(e)
235
- (options == e.options) && (inheritable_setting.to_hash == e.inheritable_setting.to_hash)
234
+ def equals?(endpoint)
235
+ (options == endpoint.options) && (inheritable_setting.to_hash == endpoint.inheritable_setting.to_hash)
236
236
  end
237
237
 
238
238
  protected
@@ -4,7 +4,7 @@ module Grape
4
4
  module Exceptions
5
5
  class ValidationErrors < Grape::Exceptions::Base
6
6
  ERRORS_FORMAT_KEY = 'grape.errors.format'
7
- DEFAULT_ERRORS_FORMAT = '%{attributes} %{message}'
7
+ DEFAULT_ERRORS_FORMAT = '%<attributes>s %<message>s'
8
8
 
9
9
  include Enumerable
10
10
 
@@ -74,7 +74,7 @@ module Grape
74
74
  end
75
75
 
76
76
  def mime_types
77
- @mime_type ||= content_types.each_pair.with_object({}) do |(k, v), types_without_params|
77
+ @mime_types ||= content_types.each_pair.with_object({}) do |(k, v), types_without_params|
78
78
  types_without_params[v.split(';').first] = k
79
79
  end
80
80
  end
@@ -74,8 +74,8 @@ module Grape
74
74
  rack_response(status, headers, format_message(message, backtrace, original_exception))
75
75
  end
76
76
 
77
- def default_rescue_handler(e)
78
- error_response(message: e.message, backtrace: e.backtrace, original_exception: e)
77
+ def default_rescue_handler(exception)
78
+ error_response(message: exception.message, backtrace: exception.backtrace, original_exception: exception)
79
79
  end
80
80
 
81
81
  def rescue_handler_for_base_only_class(klass)
@@ -57,8 +57,8 @@ module Grape
57
57
  middlewares.last
58
58
  end
59
59
 
60
- def [](i)
61
- middlewares[i]
60
+ def [](index)
61
+ middlewares[index]
62
62
  end
63
63
 
64
64
  def insert(index, *args, &block)
data/lib/grape/router.rb CHANGED
@@ -138,7 +138,8 @@ module Grape
138
138
  end
139
139
 
140
140
  def default_response
141
- [404, { Grape::Http::Headers::X_CASCADE => 'pass' }, ['404 Not Found']]
141
+ headers = Grape::Util::Header.new.merge(Grape::Http::Headers::X_CASCADE => 'pass')
142
+ [404, headers, ['404 Not Found']]
142
143
  end
143
144
 
144
145
  def match?(input, method)
@@ -21,6 +21,7 @@ module Grape
21
21
  private
22
22
 
23
23
  def do_each(params_to_process, parent_indicies = [], &block)
24
+ @scope.reset_index # gets updated depending on the size of params_to_process
24
25
  params_to_process.each_with_index do |resource_params, index|
25
26
  # when we get arrays of arrays it means that target element located inside array
26
27
  # we need this because we want to know parent arrays indicies
@@ -93,9 +93,7 @@ module Grape
93
93
 
94
94
  def meets_dependency?(params, request_params)
95
95
  return true unless @dependent_on
96
-
97
96
  return false if @parent.present? && !@parent.meets_dependency?(@parent.params(request_params), request_params)
98
-
99
97
  return params.any? { |param| meets_dependency?(param, request_params) } if params.is_a?(Array)
100
98
 
101
99
  meets_hash_dependency?(params)
@@ -103,7 +101,6 @@ module Grape
103
101
 
104
102
  def attr_meets_dependency?(params)
105
103
  return true unless @dependent_on
106
-
107
104
  return false if @parent.present? && !@parent.attr_meets_dependency?(params)
108
105
 
109
106
  meets_hash_dependency?(params)
@@ -169,6 +166,10 @@ module Grape
169
166
  !@optional
170
167
  end
171
168
 
169
+ def reset_index
170
+ @index = nil
171
+ end
172
+
172
173
  protected
173
174
 
174
175
  # Adds a parameter declaration to our list of validations.
@@ -297,12 +298,7 @@ module Grape
297
298
  # `optional` invocation that opened this scope.
298
299
  # @yield parameter scope
299
300
  def new_group_scope(attrs, &block)
300
- self.class.new(
301
- api: @api,
302
- parent: self,
303
- group: attrs.first,
304
- &block
305
- )
301
+ self.class.new(api: @api, parent: self, group: attrs.first, &block)
306
302
  end
307
303
 
308
304
  # Pushes declared params to parent or settings
@@ -7,7 +7,7 @@ module Grape
7
7
  def validate_params!(params)
8
8
  keys = keys_in_common(params)
9
9
  return if keys.length == 1
10
- raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.length.zero?
10
+ raise Grape::Exceptions::Validation.new(params: all_keys, message: message(:exactly_one)) if keys.empty?
11
11
 
12
12
  raise Grape::Exceptions::Validation.new(params: keys, message: message(:mutual_exclusion))
13
13
  end
data/lib/grape/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Grape
4
4
  # The current version of Grape.
5
- VERSION = '2.1.0'
5
+ VERSION = '2.1.2'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -189,7 +189,6 @@ files:
189
189
  - lib/grape/serve_stream/sendfile_response.rb
190
190
  - lib/grape/serve_stream/stream_response.rb
191
191
  - lib/grape/types/invalid_value.rb
192
- - lib/grape/util/accept/header.rb
193
192
  - lib/grape/util/accept_header_handler.rb
194
193
  - lib/grape/util/base_inheritable.rb
195
194
  - lib/grape/util/cache.rb
@@ -252,9 +251,9 @@ licenses:
252
251
  - MIT
253
252
  metadata:
254
253
  bug_tracker_uri: https://github.com/ruby-grape/grape/issues
255
- changelog_uri: https://github.com/ruby-grape/grape/blob/v2.1.0/CHANGELOG.md
256
- documentation_uri: https://www.rubydoc.info/gems/grape/2.1.0
257
- source_code_uri: https://github.com/ruby-grape/grape/tree/v2.1.0
254
+ changelog_uri: https://github.com/ruby-grape/grape/blob/v2.1.2/CHANGELOG.md
255
+ documentation_uri: https://www.rubydoc.info/gems/grape/2.1.2
256
+ source_code_uri: https://github.com/ruby-grape/grape/tree/v2.1.2
258
257
  post_install_message:
259
258
  rdoc_options: []
260
259
  require_paths:
@@ -270,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
269
  - !ruby/object:Gem::Version
271
270
  version: '0'
272
271
  requirements: []
273
- rubygems_version: 3.5.7
272
+ rubygems_version: 3.5.13
274
273
  signing_key:
275
274
  specification_version: 4
276
275
  summary: A simple Ruby framework for building REST-like APIs.
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Grape
4
- module Util
5
- module Accept
6
- module Header
7
- ALLOWED_CHARACTERS = %r{^([a-z*]+)/([a-z0-9*&\^\-_#{$ERROR_INFO}.+]+)(?:;([a-z0-9=;]+))?$}.freeze
8
- class << self
9
- # Corrected version of https://github.com/mjackson/rack-accept/blob/master/lib/rack/accept/header.rb#L40-L44
10
- def parse_media_type(media_type)
11
- # see http://tools.ietf.org/html/rfc6838#section-4.2 for allowed characters in media type names
12
- m = media_type&.match(ALLOWED_CHARACTERS)
13
- m ? [m[1], m[2], m[3] || ''] : []
14
- end
15
- end
16
- end
17
- end
18
- end
19
- end