grape 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ff753adfdf2428ba49d22317b87ff7a526845e582496dd6f653c8ff04261166
4
- data.tar.gz: b62d8ab4c9ac3ca28d62bb2e9afaae54255ed820be17029da35498111ff98cb7
3
+ metadata.gz: 024e352cc91ca60c4f0750b852ce4fba0dc574b33d647ef10958b4db12fc7090
4
+ data.tar.gz: d9fb3be3da671011a1bed81d5f986a1688d411903bcf550c9d6ea83c7dcb6e0f
5
5
  SHA512:
6
- metadata.gz: 4501a8f8141b54f83a6e289d0dc9e1128273b92a23a4116f892ef2b47feb03fb852f6787d151a02f553665a5cdb3ac34e440f468ab4901a02c436340bde27f32
7
- data.tar.gz: 861d46d98bb44caf203c5e6f919ecf568174a5d915259df983f66310c4c9b118213c62b489c8e498569ea2eebf0a8bf65a0b0888fb4d14e97e408e1f3a12c5fe
6
+ metadata.gz: 6172f2a8d7567edcbebb7289d5e41bed65f66ffa9309dd37b03b57cf199bc84945cdfd241df84e6a92ecf28f9099b18b9fe08516470b38721cb256fce5de8a34
7
+ data.tar.gz: d5ce8b9292bc9e596a955ac0c748cb2c278daf68246192556a1ee91e726026bdced1586ea4b73818727ff3fd2b0f32df57f3674d7a5f585703cd91c7630f5b71
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
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
+
1
9
  ### 2.1.1 (2024-06-22)
2
10
 
3
11
  #### 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.1**.
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)
@@ -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)
@@ -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.1'
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.1
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-22 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.1/CHANGELOG.md
256
- documentation_uri: https://www.rubydoc.info/gems/grape/2.1.1
257
- source_code_uri: https://github.com/ruby-grape/grape/tree/v2.1.1
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:
@@ -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