grape 0.19.0 → 0.19.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grape might be problematic. Click here for more details.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b5959c55c9de8f187ba61237f85df40b8d5a350d
4
- data.tar.gz: c9326028a122dd6c7f6574e5ebeabe5e64172b85
3
+ metadata.gz: a67815e028381f58318d1696015bc15108c15d17
4
+ data.tar.gz: 52eb9bc3836e2261415148134369dc1e847d8acc
5
5
  SHA512:
6
- metadata.gz: 2bc47755123872f9aabab1b2a9a842a01a4fc085a7f04df490dca0f7e06ab9ce6739c921f1897c87d988181d91c705ace17408a6fa9bd0fa26e0cf7de18cc9c4
7
- data.tar.gz: 54374eaadeb3a8ae9855381f7e87919c78aff99377caf00c025e15f37ee46468261990b686591331be8a34303233e6ea1fedcaab8c81f295491fae48e2cbf7df
6
+ metadata.gz: 65f9e5ba3c187e41e720bcdeb8727add1d53ba8f4ca68a70e122f87144bb31fc5d20a00583f9a54b41deb7d55a9fdfc9d27dcd26d91b2108e30a0ade4877b6ba
7
+ data.tar.gz: a35afb5adb3a6dc7a7cc356081d6e9bbb011e22010d388906d3a719722fff6cbdf6eb86697667695d80b6ca1ee2f045410ff214c363371e3fd569c82c51eb73b
data/Appraisals CHANGED
@@ -14,3 +14,7 @@ end
14
14
  appraise 'rack-1.5.2' do
15
15
  gem 'rack', '1.5.2'
16
16
  end
17
+
18
+ appraise 'rails-edge' do
19
+ gem 'arel', github: 'rails/arel'
20
+ end
@@ -1,3 +1,15 @@
1
+ ### 0.19.1 (1/9/2017)
2
+
3
+ #### Features
4
+
5
+ * [#1536](https://github.com/ruby-grape/grape/pull/1536): Updates `invalid_versioner_option` translation - [@Lavode](https://github.com/Lavode).
6
+ * [#1543](https://github.com/ruby-grape/grape/pull/1543): Support ruby 2.4 - [@LeFnord](https://github.com/LeFnord), [@namusyaka](https://github.com/namusyaka).
7
+
8
+ #### Fixes
9
+
10
+ * [#1548](https://github.com/ruby-grape/grape/pull/1548): Avoid failing even if given path does not match with prefix - [@thomas-peyric](https://github.com/thomas-peyric), [@namusyaka](https://github.com/namusyaka).
11
+ * [#1550](https://github.com/ruby-grape/grape/pull/1550): Use 200 as default status for deletes that reply with content - [@jthornec](https://github.com/jthornec).
12
+
1
13
  ### 0.19.0 (12/18/2016)
2
14
 
3
15
  #### Features
@@ -42,7 +54,6 @@
42
54
  * [#1398](https://github.com/ruby-grape/grape/pull/1398): Add `rescue_from :grape_exceptions` - allow Grape to use the built-in `Grape::Exception` handing and use `rescue :all` behavior for everything else - [@mmclead](https://github.com/mmclead).
43
55
  * [#1443](https://github.com/ruby-grape/grape/pull/1443): Extend `given` to receive a `Proc` - [@glaucocustodio](https://github.com/glaucocustodio).
44
56
  * [#1455](https://github.com/ruby-grape/grape/pull/1455): Add an automated PR linter - [@orta](https://github.com/orta).
45
- * Your contribution here.
46
57
 
47
58
  #### Fixes
48
59
 
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape (0.19.0)
4
+ grape (0.19.1)
5
5
  activesupport
6
6
  builder
7
7
  hashie (>= 2.1.0)
data/README.md CHANGED
@@ -32,6 +32,7 @@
32
32
  - [Include Missing](#include-missing)
33
33
  - [Parameter Validation and Coercion](#parameter-validation-and-coercion)
34
34
  - [Supported Parameter Types](#supported-parameter-types)
35
+ - [Integer/Fixnum and Coercions](#integerfixnum-and-coercions)
35
36
  - [Custom Types and Coercions](#custom-types-and-coercions)
36
37
  - [Multipart File Parameters](#multipart-file-parameters)
37
38
  - [First-Class `JSON` Types](#first-class-json-types)
@@ -105,7 +106,7 @@ content negotiation, versioning and much more.
105
106
 
106
107
  ## Stable Release
107
108
 
108
- You're reading the documentation for the stable release of Grape, 0.19.0.
109
+ You're reading the documentation for the stable release of Grape, 0.19.1.
109
110
  Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
110
111
 
111
112
  ## Project Resources
@@ -798,6 +799,28 @@ The following are all valid types, supported out of the box by Grape:
798
799
  * Rack::Multipart::UploadedFile (alias `File`)
799
800
  * JSON
800
801
 
802
+ ### Integer/Fixnum and Coercions
803
+
804
+ Please be aware that the behavior differs between Ruby 2.4 and earlier versions.
805
+ In Ruby 2.4, values consisting of numbers are converted to Integer, but in earlier versions it will be treated as Fixnum.
806
+
807
+ ```ruby
808
+ params do
809
+ requires :integers, type: Hash do
810
+ requires :int, coerce: Integer
811
+ end
812
+ end
813
+ get '/int' do
814
+ params[:integers][:int].class
815
+ end
816
+
817
+ ...
818
+
819
+ get '/int' integers: { int: '45' }
820
+ #=> Integer in ruby 2.4
821
+ #=> Fixnum in earlier ruby versions
822
+ ```
823
+
801
824
  ### Custom Types and Coercions
802
825
 
803
826
  Aside from the default set of supported types listed above, any class can be
@@ -1740,7 +1763,7 @@ cookies.delete :status_count, path: '/'
1740
1763
 
1741
1764
  ## HTTP Status Code
1742
1765
 
1743
- By default Grape returns a 201 for `POST`-Requests, 204 for `DELETE`-Requests and 200 status code for all other Requests.
1766
+ By default Grape returns a 201 for `POST`-Requests, 204 for `DELETE`-Requests that don't return any content, and 200 status code for all other Requests.
1744
1767
  You can use `status` to query and set the actual HTTP Status Code
1745
1768
 
1746
1769
  ```ruby
@@ -2183,6 +2206,14 @@ class API < Grape::API
2183
2206
  end
2184
2207
  ```
2185
2208
 
2209
+ To change the logger level.
2210
+
2211
+ ```ruby
2212
+ class API < Grape::API
2213
+ self.logger.level = Logger::INFO
2214
+ end
2215
+ ```
2216
+
2186
2217
  You can also set your own logger.
2187
2218
 
2188
2219
  ```ruby
@@ -2877,7 +2908,7 @@ end
2877
2908
  The behaviour is then:
2878
2909
 
2879
2910
  ```bash
2880
- GET /123 # 'Fixnum'
2911
+ GET /123 # 'Integer'
2881
2912
  GET /foo # 400 error - 'blah is invalid'
2882
2913
  ```
2883
2914
 
@@ -36,8 +36,7 @@ You're reading the documentation for the stable release of Grape, 0.6.0.
36
36
  Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
37
37
 
38
38
  ```
39
- 0.6.0 (9/16/2013)
40
- =================
39
+ #### 0.6.0 (9/16/2013)
41
40
  ```
42
41
 
43
42
  Remove the line with "Your contribution here.", since there will be no more contributions to this release.
@@ -75,8 +74,7 @@ The current stable release is [0.6.0](https://github.com/ruby-grape/grape/blob/v
75
74
  Add the next release to [CHANGELOG.md](CHANGELOG.md).
76
75
 
77
76
  ```
78
- Next Release
79
- ============
77
+ #### 0.6.1 (Next)
80
78
 
81
79
  * Your contribution here.
82
80
  ```
@@ -89,7 +87,7 @@ module Grape
89
87
  end
90
88
  ```
91
89
 
92
- Comit your changes.
90
+ Commit your changes.
93
91
 
94
92
  ```
95
93
  git add CHANGELOG.md README.md lib/grape/version.rb
@@ -1,6 +1,38 @@
1
1
  Upgrading Grape
2
2
  ===============
3
3
 
4
+ ### Upgrading to >= 0.19.1 (next)
5
+
6
+ #### DELETE now defaults to status code 200 for responses with a body, or 204 otherwise
7
+
8
+ Prior to this version, DELETE requests defaulted to a status code of 204 No Content, even when the response included content. This behavior confused some clients and prevented the formatter middleware from running properly. As of this version, DELETE requests will only default to a 204 No Content status code if no response body is provided, and will default to 200 OK otherwise.
9
+
10
+ Specifically, DELETE behaviour has changed as follows:
11
+
12
+ - In versions < 0.19.0, all DELETE requests defaulted to a 200 OK status code.
13
+ - In version 0.19.0, all DELETE requests defaulted to a 204 No Content status code, even when content was included in the response.
14
+ - As of version 0.19.1, DELETE requests default to a 204 No Content status code, unless content is supplied, in which case they default to a 200 OK status code.
15
+
16
+ To achieve the old behavior, one can specify the status code explicitly:
17
+
18
+ ```ruby
19
+ delete :id do
20
+ status 204 # or 200, for < 0.19.0 behavior
21
+ 'foo successfully deleted'
22
+ end
23
+ ```
24
+
25
+ One can also use the new `return_no_content` helper to explicitly return a 204 status code and an empty body for any request type:
26
+
27
+ ```ruby
28
+ delete :id do
29
+ return_no_content
30
+ 'this will not be returned'
31
+ end
32
+ ```
33
+
34
+ See [#1550](https://github.com/ruby-grape/grape/pull/1550) for more information.
35
+
4
36
  ### Upgrading to >= 0.18.1
5
37
 
6
38
  #### Changes in priority of :any routes
@@ -2,12 +2,12 @@
2
2
 
3
3
  source 'https://rubygems.org'
4
4
 
5
- gem 'rails', github: 'rails/rails'
5
+ gem 'arel', github: 'rails/arel'
6
6
 
7
7
  group :development, :test do
8
8
  gem 'bundler'
9
9
  gem 'rake'
10
- gem 'rubocop', '~> 0.45.0'
10
+ gem 'rubocop', '~> 0.45'
11
11
  end
12
12
 
13
13
  group :development do
@@ -122,7 +122,7 @@ module Grape
122
122
  when Symbol
123
123
  raise ArgumentError, "Status code :#{status} is invalid." unless Rack::Utils::SYMBOL_TO_STATUS_CODE.keys.include?(status)
124
124
  @status = Rack::Utils.status_code(status)
125
- when Fixnum
125
+ when Integer
126
126
  @status = status
127
127
  when nil
128
128
  return @status if @status
@@ -130,12 +130,16 @@ module Grape
130
130
  when Grape::Http::Headers::POST
131
131
  201
132
132
  when Grape::Http::Headers::DELETE
133
- 204
133
+ if @body.present?
134
+ 200
135
+ else
136
+ 204
137
+ end
134
138
  else
135
139
  200
136
140
  end
137
141
  else
138
- raise ArgumentError, 'Status code must be Fixnum or Symbol.'
142
+ raise ArgumentError, 'Status code must be Integer or Symbol.'
139
143
  end
140
144
  end
141
145
 
@@ -181,6 +185,20 @@ module Grape
181
185
  end
182
186
  end
183
187
 
188
+ # Allows you to explicitly return no content.
189
+ #
190
+ # @example
191
+ # delete :id do
192
+ # return_no_content
193
+ # "not returned"
194
+ # end
195
+ #
196
+ # DELETE /12 # => 204 No Content, ""
197
+ def return_no_content
198
+ status 204
199
+ body false
200
+ end
201
+
184
202
  # Allows you to define the response as a file-like object.
185
203
  #
186
204
  # @example
@@ -26,7 +26,7 @@ en:
26
26
  invalid_formatter: 'cannot convert %{klass} to %{to_format}'
27
27
  invalid_versioner_option:
28
28
  problem: 'Unknown :using for versioner: %{strategy}'
29
- resolution: 'available strategy for :using is :path, :header, :param'
29
+ resolution: 'available strategy for :using is :path, :header, :accept_version_header, :param'
30
30
  unknown_validator: 'unknown validator: %{validator_type}'
31
31
  unknown_options: 'unknown options: %{options}'
32
32
  unknown_parameter: 'unknown parameter: %{param}'
@@ -26,7 +26,7 @@ module Grape
26
26
  def before
27
27
  path = env[Grape::Http::Headers::PATH_INFO].dup
28
28
 
29
- if prefix && path.index(prefix).zero?
29
+ if prefix && path.index(prefix) == 0 # rubocop:disable all
30
30
  path.sub!(prefix, '')
31
31
  path = Grape::Router.normalize_path(path)
32
32
  end
@@ -1,4 +1,4 @@
1
1
  module Grape
2
2
  # The current version of Grape.
3
- VERSION = '0.19.0'.freeze
3
+ VERSION = '0.19.1'.freeze
4
4
  end
@@ -925,7 +925,7 @@ XML
925
925
  end
926
926
 
927
927
  get '/', id: '32'
928
- expect(last_response.body).to eql 'first 32:Fixnum second'
928
+ expect(last_response.body).to eql "first 32:#{integer_class_name} second"
929
929
  end
930
930
 
931
931
  it 'adds a after filter' do
@@ -2506,7 +2506,7 @@ XML
2506
2506
  end
2507
2507
  end
2508
2508
  describe 'status' do
2509
- it 'can be set to arbitrary Fixnum value' do
2509
+ it 'can be set to arbitrary Integer value' do
2510
2510
  subject.get '/foo' do
2511
2511
  status 210
2512
2512
  end
@@ -111,6 +111,13 @@ describe Grape::Endpoint do
111
111
  expect(subject.status).to eq 204
112
112
  end
113
113
 
114
+ it 'defaults to 200 on DELETE with a body present' do
115
+ request = Grape::Request.new(Rack::MockRequest.env_for('/', method: 'DELETE'))
116
+ subject.body 'content here'
117
+ expect(subject).to receive(:request).and_return(request)
118
+ expect(subject.status).to eq 200
119
+ end
120
+
114
121
  it 'returns status set' do
115
122
  subject.status 501
116
123
  expect(subject.status).to eq 501
@@ -126,13 +133,21 @@ describe Grape::Endpoint do
126
133
  .to raise_error(ArgumentError, 'Status code :foo_bar is invalid.')
127
134
  end
128
135
 
129
- it 'accepts unknown Fixnum status codes' do
136
+ it 'accepts unknown Integer status codes' do
130
137
  expect { subject.status 210 }.to_not raise_error
131
138
  end
132
139
 
133
- it 'raises error if status is not a fixnum or symbol' do
140
+ it 'raises error if status is not a integer or symbol' do
134
141
  expect { subject.status Object.new }
135
- .to raise_error(ArgumentError, 'Status code must be Fixnum or Symbol.')
142
+ .to raise_error(ArgumentError, 'Status code must be Integer or Symbol.')
143
+ end
144
+ end
145
+
146
+ describe '#return_no_content' do
147
+ it 'sets the status code and body' do
148
+ subject.return_no_content
149
+ expect(subject.status).to eq 204
150
+ expect(subject.body).to eq ''
136
151
  end
137
152
  end
138
153
 
@@ -131,7 +131,7 @@ module Grape
131
131
  end
132
132
 
133
133
  it 'abort if :with option value is not Symbol, String or Proc' do
134
- expect { subject.rescue_from :all, with: 1234 }.to raise_error(ArgumentError, 'with: Fixnum, expected Symbol, String or Proc')
134
+ expect { subject.rescue_from :all, with: 1234 }.to raise_error(ArgumentError, "with: #{integer_class_name}, expected Symbol, String or Proc")
135
135
  end
136
136
 
137
137
  it 'abort if both :with option and block are passed' do
@@ -41,4 +41,11 @@ describe Grape::Middleware::Versioner::Path do
41
41
  end
42
42
  end
43
43
  end
44
+
45
+ context 'with prefix, but requested version is not matched' do
46
+ let(:options) { { prefix: '/v1', pattern: /v./i } }
47
+ it 'recognizes potential version' do
48
+ expect(subject.call('PATH_INFO' => '/v3/foo').last).to eq('v3')
49
+ end
50
+ end
44
51
  end
@@ -57,9 +57,9 @@ describe Grape::Validations::AllowBlankValidator do
57
57
  get '/allow_float_blank'
58
58
 
59
59
  params do
60
- requires :val, type: Fixnum, allow_blank: true
60
+ requires :val, type: Integer, allow_blank: true
61
61
  end
62
- get '/allow_fixnum_blank'
62
+ get '/allow_integer_blank'
63
63
 
64
64
  params do
65
65
  requires :val, type: Symbol, allow_blank: true
@@ -173,9 +173,9 @@ describe Grape::Validations::AllowBlankValidator do
173
173
  get '/allow_float_blank'
174
174
 
175
175
  params do
176
- requires :val, type: Fixnum, allow_blank: true
176
+ requires :val, type: Integer, allow_blank: true
177
177
  end
178
- get '/allow_fixnum_blank'
178
+ get '/allow_integer_blank'
179
179
 
180
180
  params do
181
181
  requires :val, type: Symbol, allow_blank: true
@@ -345,8 +345,8 @@ describe Grape::Validations::AllowBlankValidator do
345
345
  expect(last_response.status).to eq(200)
346
346
  end
347
347
 
348
- it 'accepts empty when fixnum allow_blank' do
349
- get '/custom_message/allow_fixnum_blank', val: ''
348
+ it 'accepts empty when integer allow_blank' do
349
+ get '/custom_message/allow_integer_blank', val: ''
350
350
  expect(last_response.status).to eq(200)
351
351
  end
352
352
  end
@@ -483,8 +483,8 @@ describe Grape::Validations::AllowBlankValidator do
483
483
  expect(last_response.status).to eq(200)
484
484
  end
485
485
 
486
- it 'accepts empty when fixnum allow_blank' do
487
- get '/allow_fixnum_blank', val: ''
486
+ it 'accepts empty when integer allow_blank' do
487
+ get '/allow_integer_blank', val: ''
488
488
  expect(last_response.status).to eq(200)
489
489
  end
490
490
  end
@@ -175,7 +175,7 @@ describe Grape::Validations::CoerceValidator do
175
175
 
176
176
  get '/int', int: '45'
177
177
  expect(last_response.status).to eq(200)
178
- expect(last_response.body).to eq('Fixnum')
178
+ expect(last_response.body).to eq(integer_class_name)
179
179
  end
180
180
 
181
181
  context 'Array' do
@@ -189,7 +189,7 @@ describe Grape::Validations::CoerceValidator do
189
189
 
190
190
  get '/array', arry: %w(1 2 3)
191
191
  expect(last_response.status).to eq(200)
192
- expect(last_response.body).to eq('Fixnum')
192
+ expect(last_response.body).to eq(integer_class_name)
193
193
  end
194
194
 
195
195
  it 'Array of Bools' do
@@ -238,7 +238,7 @@ describe Grape::Validations::CoerceValidator do
238
238
 
239
239
  get '/set', set: Set.new([1, 2, 3, 4]).to_a
240
240
  expect(last_response.status).to eq(200)
241
- expect(last_response.body).to eq('Fixnum')
241
+ expect(last_response.body).to eq(integer_class_name)
242
242
  end
243
243
 
244
244
  it 'Set of Bools' do
@@ -326,7 +326,7 @@ describe Grape::Validations::CoerceValidator do
326
326
 
327
327
  get '/int', integers: { int: '45' }
328
328
  expect(last_response.status).to eq(200)
329
- expect(last_response.body).to eq('Fixnum')
329
+ expect(last_response.body).to eq(integer_class_name)
330
330
  end
331
331
  end
332
332
 
@@ -525,11 +525,11 @@ describe Grape::Validations::CoerceValidator do
525
525
 
526
526
  get '/', splines: '{"x":"1","y":"woof"}'
527
527
  expect(last_response.status).to eq(200)
528
- expect(last_response.body).to eq('Fixnum.String')
528
+ expect(last_response.body).to eq("#{integer_class_name}.String")
529
529
 
530
530
  get '/', splines: '[{"x":1,"y":2},{"x":1,"y":"quack"}]'
531
531
  expect(last_response.status).to eq(200)
532
- expect(last_response.body).to eq('Fixnum.Fixnum')
532
+ expect(last_response.body).to eq("#{integer_class_name}.#{integer_class_name}")
533
533
 
534
534
  get '/', splines: '{"x":"4","y":"woof"}'
535
535
  expect(last_response.status).to eq(400)
@@ -576,7 +576,7 @@ describe Grape::Validations::CoerceValidator do
576
576
 
577
577
  get '/', a: '5'
578
578
  expect(last_response.status).to eq(200)
579
- expect(last_response.body).to eq('Fixnum')
579
+ expect(last_response.body).to eq(integer_class_name)
580
580
 
581
581
  get '/', a: 'anything else'
582
582
  expect(last_response.status).to eq(200)
@@ -16,6 +16,7 @@ I18n.enforce_available_locales = false
16
16
 
17
17
  RSpec.configure do |config|
18
18
  config.include Rack::Test::Methods
19
+ config.include Spec::Support::Helpers
19
20
  config.raise_errors_for_deprecations!
20
21
 
21
22
  config.before(:each) { Grape::Util::InheritableSetting.reset_global! }
@@ -1,3 +1,9 @@
1
- def encode_basic_auth(username, password)
2
- 'Basic ' + Base64.encode64("#{username}:#{password}")
1
+ module Spec
2
+ module Support
3
+ module Helpers
4
+ def encode_basic_auth(username, password)
5
+ 'Basic ' + Base64.encode64("#{username}:#{password}")
6
+ end
7
+ end
8
+ end
3
9
  end
@@ -1,11 +1,13 @@
1
- module ContentTypeHelpers
2
- %w(put patch post delete).each do |method|
3
- define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block|
4
- params = params.to_json
5
- env['CONTENT_TYPE'] ||= 'application/json'
6
- send(method, uri, params, env, &block)
1
+ module Spec
2
+ module Support
3
+ module Helpers
4
+ %w(put patch post delete).each do |method|
5
+ define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block|
6
+ params = params.to_json
7
+ env['CONTENT_TYPE'] ||= 'application/json'
8
+ send(method, uri, params, env, &block)
9
+ end
10
+ end
7
11
  end
8
12
  end
9
13
  end
10
-
11
- include(ContentTypeHelpers)
@@ -0,0 +1,11 @@
1
+ module Spec
2
+ module Support
3
+ module Helpers
4
+ INTEGER_CLASS_NAME = 0.to_i.class.to_s.freeze
5
+
6
+ def integer_class_name
7
+ INTEGER_CLASS_NAME
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,50 +1,55 @@
1
1
  # Versioning
2
+ module Spec
3
+ module Support
4
+ module Helpers
5
+ # Returns the path with options[:version] prefixed if options[:using] is :path.
6
+ # Returns normal path otherwise.
7
+ def versioned_path(options = {})
8
+ case options[:using]
9
+ when :path
10
+ File.join('/', options[:prefix] || '', options[:version], options[:path])
11
+ when :param
12
+ File.join('/', options[:prefix] || '', options[:path])
13
+ when :header
14
+ File.join('/', options[:prefix] || '', options[:path])
15
+ when :accept_version_header
16
+ File.join('/', options[:prefix] || '', options[:path])
17
+ else
18
+ raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
19
+ end
20
+ end
2
21
 
3
- # Returns the path with options[:version] prefixed if options[:using] is :path.
4
- # Returns normal path otherwise.
5
- def versioned_path(options = {})
6
- case options[:using]
7
- when :path
8
- File.join('/', options[:prefix] || '', options[:version], options[:path])
9
- when :param
10
- File.join('/', options[:prefix] || '', options[:path])
11
- when :header
12
- File.join('/', options[:prefix] || '', options[:path])
13
- when :accept_version_header
14
- File.join('/', options[:prefix] || '', options[:path])
15
- else
16
- raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
17
- end
18
- end
19
-
20
- def versioned_headers(options)
21
- case options[:using]
22
- when :path
23
- {} # no-op
24
- when :param
25
- {} # no-op
26
- when :header
27
- {
28
- 'HTTP_ACCEPT' => [
29
- "application/vnd.#{options[:vendor]}-#{options[:version]}",
30
- options[:format]
31
- ].compact.join('+')
32
- }
33
- when :accept_version_header
34
- {
35
- 'HTTP_ACCEPT_VERSION' => options[:version].to_s
36
- }
37
- else
38
- raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
39
- end
40
- end
22
+ def versioned_headers(options)
23
+ case options[:using]
24
+ when :path
25
+ {} # no-op
26
+ when :param
27
+ {} # no-op
28
+ when :header
29
+ {
30
+ 'HTTP_ACCEPT' => [
31
+ "application/vnd.#{options[:vendor]}-#{options[:version]}",
32
+ options[:format]
33
+ ].compact.join('+')
34
+ }
35
+ when :accept_version_header
36
+ {
37
+ 'HTTP_ACCEPT_VERSION' => options[:version].to_s
38
+ }
39
+ else
40
+ raise ArgumentError.new("unknown versioning strategy: #{options[:using]}")
41
+ end
42
+ end
41
43
 
42
- def versioned_get(path, version_name, version_options = {})
43
- path = versioned_path(version_options.merge(version: version_name, path: path))
44
- headers = versioned_headers(version_options.merge(version: version_name))
45
- params = {}
46
- if version_options[:using] == :param
47
- params = { version_options[:parameter] => version_name }
44
+ def versioned_get(path, version_name, version_options = {})
45
+ path = versioned_path(version_options.merge(version: version_name, path: path))
46
+ headers = versioned_headers(version_options.merge(version: version_name))
47
+ params = {}
48
+ if version_options[:using] == :param
49
+ params = { version_options[:parameter] => version_name }
50
+ end
51
+ get path, params, headers
52
+ end
53
+ end
48
54
  end
49
- get path, params, headers
50
55
  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: 0.19.0
4
+ version: 0.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Bleigh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-19 00:00:00.000000000 Z
11
+ date: 2017-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -277,7 +277,6 @@ files:
277
277
  - lib/grape/validations/validators/regexp.rb
278
278
  - lib/grape/validations/validators/values.rb
279
279
  - lib/grape/version.rb
280
- - pkg/grape-0.17.0.gem
281
280
  - spec/grape/api/custom_validations_spec.rb
282
281
  - spec/grape/api/deeply_included_options_spec.rb
283
282
  - spec/grape/api/invalid_format_spec.rb
@@ -364,6 +363,7 @@ files:
364
363
  - spec/support/content_type_helpers.rb
365
364
  - spec/support/endpoint_faker.rb
366
365
  - spec/support/file_streamer.rb
366
+ - spec/support/integer_helpers.rb
367
367
  - spec/support/versioned_helpers.rb
368
368
  homepage: https://github.com/ruby-grape/grape
369
369
  licenses:
@@ -476,4 +476,5 @@ test_files:
476
476
  - spec/support/content_type_helpers.rb
477
477
  - spec/support/endpoint_faker.rb
478
478
  - spec/support/file_streamer.rb
479
+ - spec/support/integer_helpers.rb
479
480
  - spec/support/versioned_helpers.rb
Binary file