grape 0.9.0 → 0.10.0
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 +4 -4
- data/.rubocop.yml +1 -66
- data/.rubocop_todo.yml +78 -17
- data/.travis.yml +7 -3
- data/Appraisals +7 -0
- data/CHANGELOG.md +24 -0
- data/CONTRIBUTING.md +7 -0
- data/Gemfile +1 -7
- data/Guardfile +1 -1
- data/README.md +560 -94
- data/RELEASING.md +1 -1
- data/Rakefile +10 -11
- data/UPGRADING.md +211 -3
- data/gemfiles/rails_3.gemfile +14 -0
- data/gemfiles/rails_4.gemfile +14 -0
- data/grape.gemspec +10 -9
- data/lib/backports/active_support/deep_dup.rb +49 -0
- data/lib/backports/active_support/duplicable.rb +88 -0
- data/lib/grape.rb +29 -2
- data/lib/grape/api.rb +59 -65
- data/lib/grape/dsl/api.rb +19 -0
- data/lib/grape/dsl/callbacks.rb +6 -4
- data/lib/grape/dsl/configuration.rb +49 -5
- data/lib/grape/dsl/helpers.rb +7 -8
- data/lib/grape/dsl/inside_route.rb +22 -10
- data/lib/grape/dsl/middleware.rb +5 -5
- data/lib/grape/dsl/parameters.rb +6 -2
- data/lib/grape/dsl/request_response.rb +23 -20
- data/lib/grape/dsl/routing.rb +52 -49
- data/lib/grape/dsl/settings.rb +110 -0
- data/lib/grape/dsl/validations.rb +14 -6
- data/lib/grape/endpoint.rb +104 -88
- data/lib/grape/exceptions/base.rb +2 -2
- data/lib/grape/exceptions/incompatible_option_values.rb +1 -1
- data/lib/grape/exceptions/invalid_formatter.rb +1 -1
- data/lib/grape/exceptions/invalid_versioner_option.rb +1 -1
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +1 -1
- data/lib/grape/exceptions/missing_mime_type.rb +1 -1
- data/lib/grape/exceptions/missing_option.rb +1 -1
- data/lib/grape/exceptions/missing_vendor_option.rb +1 -1
- data/lib/grape/exceptions/unknown_options.rb +1 -1
- data/lib/grape/exceptions/unknown_validator.rb +1 -1
- data/lib/grape/exceptions/validation.rb +1 -1
- data/lib/grape/exceptions/validation_errors.rb +2 -2
- data/lib/grape/formatter/serializable_hash.rb +1 -1
- data/lib/grape/formatter/xml.rb +1 -1
- data/lib/grape/locale/en.yml +2 -0
- data/lib/grape/middleware/auth/dsl.rb +26 -21
- data/lib/grape/middleware/auth/strategies.rb +1 -1
- data/lib/grape/middleware/auth/strategy_info.rb +0 -2
- data/lib/grape/middleware/base.rb +2 -2
- data/lib/grape/middleware/error.rb +1 -1
- data/lib/grape/middleware/formatter.rb +5 -5
- data/lib/grape/middleware/versioner.rb +1 -1
- data/lib/grape/middleware/versioner/header.rb +3 -3
- data/lib/grape/middleware/versioner/param.rb +2 -2
- data/lib/grape/middleware/versioner/path.rb +1 -1
- data/lib/grape/namespace.rb +1 -1
- data/lib/grape/path.rb +9 -3
- data/lib/grape/util/content_types.rb +16 -8
- data/lib/grape/util/inheritable_setting.rb +74 -0
- data/lib/grape/util/inheritable_values.rb +51 -0
- data/lib/grape/util/stackable_values.rb +52 -0
- data/lib/grape/util/strict_hash_configuration.rb +106 -0
- data/lib/grape/validations.rb +0 -220
- data/lib/grape/validations/attributes_iterator.rb +21 -0
- data/lib/grape/validations/params_scope.rb +176 -0
- data/lib/grape/validations/validators/all_or_none.rb +20 -0
- data/lib/grape/validations/validators/allow_blank.rb +30 -0
- data/lib/grape/validations/validators/at_least_one_of.rb +20 -0
- data/lib/grape/validations/validators/base.rb +37 -0
- data/lib/grape/validations/{coerce.rb → validators/coerce.rb} +3 -3
- data/lib/grape/validations/{default.rb → validators/default.rb} +1 -1
- data/lib/grape/validations/validators/exactly_one_of.rb +20 -0
- data/lib/grape/validations/validators/multiple_params_base.rb +26 -0
- data/lib/grape/validations/validators/mutual_exclusion.rb +25 -0
- data/lib/grape/validations/{presence.rb → validators/presence.rb} +2 -2
- data/lib/grape/validations/validators/regexp.rb +12 -0
- data/lib/grape/validations/validators/values.rb +26 -0
- data/lib/grape/version.rb +1 -1
- data/spec/grape/api_spec.rb +522 -343
- data/spec/grape/dsl/callbacks_spec.rb +4 -4
- data/spec/grape/dsl/configuration_spec.rb +48 -9
- data/spec/grape/dsl/helpers_spec.rb +6 -13
- data/spec/grape/dsl/inside_route_spec.rb +43 -4
- data/spec/grape/dsl/middleware_spec.rb +1 -10
- data/spec/grape/dsl/parameters_spec.rb +8 -1
- data/spec/grape/dsl/request_response_spec.rb +16 -22
- data/spec/grape/dsl/routing_spec.rb +21 -5
- data/spec/grape/dsl/settings_spec.rb +219 -0
- data/spec/grape/dsl/validations_spec.rb +8 -11
- data/spec/grape/endpoint_spec.rb +115 -86
- data/spec/grape/entity_spec.rb +33 -33
- data/spec/grape/exceptions/invalid_formatter_spec.rb +3 -5
- data/spec/grape/exceptions/invalid_versioner_option_spec.rb +4 -6
- data/spec/grape/exceptions/missing_mime_type_spec.rb +5 -6
- data/spec/grape/exceptions/missing_option_spec.rb +3 -5
- data/spec/grape/exceptions/unknown_options_spec.rb +3 -5
- data/spec/grape/exceptions/unknown_validator_spec.rb +3 -5
- data/spec/grape/exceptions/validation_errors_spec.rb +5 -5
- data/spec/grape/loading_spec.rb +44 -0
- data/spec/grape/middleware/auth/base_spec.rb +0 -4
- data/spec/grape/middleware/auth/dsl_spec.rb +2 -4
- data/spec/grape/middleware/auth/strategies_spec.rb +5 -6
- data/spec/grape/middleware/exception_spec.rb +8 -10
- data/spec/grape/middleware/formatter_spec.rb +13 -15
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +10 -10
- data/spec/grape/middleware/versioner/header_spec.rb +25 -25
- data/spec/grape/middleware/versioner/param_spec.rb +15 -17
- data/spec/grape/middleware/versioner/path_spec.rb +1 -2
- data/spec/grape/middleware/versioner_spec.rb +0 -1
- data/spec/grape/path_spec.rb +66 -45
- data/spec/grape/util/inheritable_setting_spec.rb +217 -0
- data/spec/grape/util/inheritable_values_spec.rb +63 -0
- data/spec/grape/util/stackable_values_spec.rb +115 -0
- data/spec/grape/util/strict_hash_configuration_spec.rb +38 -0
- data/spec/grape/validations/attributes_iterator_spec.rb +4 -0
- data/spec/grape/validations/params_scope_spec.rb +57 -0
- data/spec/grape/validations/validators/all_or_none_spec.rb +60 -0
- data/spec/grape/validations/validators/allow_blank_spec.rb +170 -0
- data/spec/grape/validations/{at_least_one_of_spec.rb → validators/at_least_one_of_spec.rb} +7 -3
- data/spec/grape/validations/{coerce_spec.rb → validators/coerce_spec.rb} +8 -11
- data/spec/grape/validations/{default_spec.rb → validators/default_spec.rb} +7 -9
- data/spec/grape/validations/{exactly_one_of_spec.rb → validators/exactly_one_of_spec.rb} +15 -11
- data/spec/grape/validations/{mutual_exclusion_spec.rb → validators/mutual_exclusion_spec.rb} +11 -9
- data/spec/grape/validations/{presence_spec.rb → validators/presence_spec.rb} +30 -30
- data/spec/grape/validations/{regexp_spec.rb → validators/regexp_spec.rb} +2 -4
- data/spec/grape/validations/{values_spec.rb → validators/values_spec.rb} +95 -23
- data/spec/grape/validations/{zh-CN.yml → validators/zh-CN.yml} +0 -0
- data/spec/grape/validations_spec.rb +335 -70
- data/spec/shared/versioning_examples.rb +7 -8
- data/spec/spec_helper.rb +2 -0
- data/spec/support/basic_auth_encode_helpers.rb +1 -1
- data/spec/support/content_type_helpers.rb +1 -1
- data/spec/support/versioned_helpers.rb +3 -3
- metadata +80 -33
- data/lib/grape/util/deep_merge.rb +0 -23
- data/lib/grape/util/hash_stack.rb +0 -120
- data/lib/grape/validations/at_least_one_of.rb +0 -25
- data/lib/grape/validations/exactly_one_of.rb +0 -26
- data/lib/grape/validations/mutual_exclusion.rb +0 -25
- data/lib/grape/validations/regexp.rb +0 -12
- data/lib/grape/validations/values.rb +0 -23
- data/spec/grape/util/hash_stack_spec.rb +0 -132
@@ -6,7 +6,7 @@ shared_examples_for 'versioning' do
|
|
6
6
|
"Version: #{request.env['api.version'] }"
|
7
7
|
end
|
8
8
|
versioned_get '/hello', 'v1', macro_options
|
9
|
-
expect(last_response.body).to eql
|
9
|
+
expect(last_response.body).to eql 'Version: v1'
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'adds the prefix before the API version' do
|
@@ -17,18 +17,18 @@ shared_examples_for 'versioning' do
|
|
17
17
|
"Version: #{request.env['api.version'] }"
|
18
18
|
end
|
19
19
|
versioned_get '/hello', 'v1', macro_options.merge(prefix: 'api')
|
20
|
-
expect(last_response.body).to eql
|
20
|
+
expect(last_response.body).to eql 'Version: v1'
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'is able to specify version as a nesting' do
|
24
24
|
subject.version 'v2', macro_options
|
25
25
|
subject.get '/awesome' do
|
26
|
-
|
26
|
+
'Radical'
|
27
27
|
end
|
28
28
|
|
29
29
|
subject.version 'v1', macro_options do
|
30
30
|
get '/legacy' do
|
31
|
-
|
31
|
+
'Totally'
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -46,7 +46,7 @@ shared_examples_for 'versioning' do
|
|
46
46
|
it 'is able to specify multiple versions' do
|
47
47
|
subject.version 'v1', 'v2', macro_options
|
48
48
|
subject.get 'awesome' do
|
49
|
-
|
49
|
+
'I exist'
|
50
50
|
end
|
51
51
|
|
52
52
|
versioned_get '/awesome', 'v1', macro_options
|
@@ -68,7 +68,7 @@ shared_examples_for 'versioning' do
|
|
68
68
|
|
69
69
|
subject.version 'v1', macro_options do
|
70
70
|
get 'version' do
|
71
|
-
|
71
|
+
'version ' + request.env['api.version']
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -92,7 +92,7 @@ shared_examples_for 'versioning' do
|
|
92
92
|
|
93
93
|
subject.version 'v1', macro_options do
|
94
94
|
get 'version' do
|
95
|
-
|
95
|
+
'version ' + request.env['api.version']
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
@@ -117,5 +117,4 @@ shared_examples_for 'versioning' do
|
|
117
117
|
versioned_get '/api_version_with_version_param?version=1', 'v1', macro_options
|
118
118
|
expect(last_response.body).to eql '1'
|
119
119
|
end
|
120
|
-
|
121
120
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,7 +2,7 @@ module ContentTypeHelpers
|
|
2
2
|
%w(put patch post delete).each do |method|
|
3
3
|
define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block|
|
4
4
|
params = params.to_json
|
5
|
-
env[
|
5
|
+
env['CONTENT_TYPE'] ||= 'application/json'
|
6
6
|
send(method, uri, params, env, &block)
|
7
7
|
end
|
8
8
|
end
|
@@ -13,7 +13,7 @@ def versioned_path(options = {})
|
|
13
13
|
when :accept_version_header
|
14
14
|
File.join('/', options[:prefix] || '', options[:path])
|
15
15
|
else
|
16
|
-
|
16
|
+
fail ArgumentError.new("unknown versioning strategy: #{options[:using]}")
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -28,14 +28,14 @@ def versioned_headers(options)
|
|
28
28
|
'HTTP_ACCEPT' => [
|
29
29
|
"application/vnd.#{options[:vendor] }-#{options[:version] }",
|
30
30
|
options[:format]
|
31
|
-
].compact.join(
|
31
|
+
].compact.join('+')
|
32
32
|
}
|
33
33
|
when :accept_version_header
|
34
34
|
{
|
35
35
|
'HTTP_ACCEPT_VERSION' => "#{options[:version] }"
|
36
36
|
}
|
37
37
|
else
|
38
|
-
|
38
|
+
fail ArgumentError.new("unknown versioning strategy: #{options[:using]}")
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
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.
|
4
|
+
version: 0.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Bleigh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -276,6 +276,20 @@ dependencies:
|
|
276
276
|
- - '>='
|
277
277
|
- !ruby/object:Gem::Version
|
278
278
|
version: '0'
|
279
|
+
- !ruby/object:Gem::Dependency
|
280
|
+
name: appraisal
|
281
|
+
requirement: !ruby/object:Gem::Requirement
|
282
|
+
requirements:
|
283
|
+
- - '>='
|
284
|
+
- !ruby/object:Gem::Version
|
285
|
+
version: '0'
|
286
|
+
type: :development
|
287
|
+
prerelease: false
|
288
|
+
version_requirements: !ruby/object:Gem::Requirement
|
289
|
+
requirements:
|
290
|
+
- - '>='
|
291
|
+
- !ruby/object:Gem::Version
|
292
|
+
version: '0'
|
279
293
|
description: A Ruby framework for rapid API development with great conventions.
|
280
294
|
email:
|
281
295
|
- michael@intridea.com
|
@@ -289,6 +303,7 @@ files:
|
|
289
303
|
- .rubocop_todo.yml
|
290
304
|
- .travis.yml
|
291
305
|
- .yardopts
|
306
|
+
- Appraisals
|
292
307
|
- CHANGELOG.md
|
293
308
|
- CONTRIBUTING.md
|
294
309
|
- Gemfile
|
@@ -298,12 +313,17 @@ files:
|
|
298
313
|
- RELEASING.md
|
299
314
|
- Rakefile
|
300
315
|
- UPGRADING.md
|
316
|
+
- gemfiles/rails_3.gemfile
|
317
|
+
- gemfiles/rails_4.gemfile
|
301
318
|
- grape.gemspec
|
302
319
|
- grape.png
|
320
|
+
- lib/backports/active_support/deep_dup.rb
|
321
|
+
- lib/backports/active_support/duplicable.rb
|
303
322
|
- lib/grape.rb
|
304
323
|
- lib/grape/api.rb
|
305
324
|
- lib/grape/api/helpers.rb
|
306
325
|
- lib/grape/cookies.rb
|
326
|
+
- lib/grape/dsl/api.rb
|
307
327
|
- lib/grape/dsl/callbacks.rb
|
308
328
|
- lib/grape/dsl/configuration.rb
|
309
329
|
- lib/grape/dsl/helpers.rb
|
@@ -312,6 +332,7 @@ files:
|
|
312
332
|
- lib/grape/dsl/parameters.rb
|
313
333
|
- lib/grape/dsl/request_response.rb
|
314
334
|
- lib/grape/dsl/routing.rb
|
335
|
+
- lib/grape/dsl/settings.rb
|
315
336
|
- lib/grape/dsl/validations.rb
|
316
337
|
- lib/grape/endpoint.rb
|
317
338
|
- lib/grape/error_formatter/base.rb
|
@@ -358,17 +379,25 @@ files:
|
|
358
379
|
- lib/grape/path.rb
|
359
380
|
- lib/grape/route.rb
|
360
381
|
- lib/grape/util/content_types.rb
|
361
|
-
- lib/grape/util/
|
362
|
-
- lib/grape/util/
|
382
|
+
- lib/grape/util/inheritable_setting.rb
|
383
|
+
- lib/grape/util/inheritable_values.rb
|
384
|
+
- lib/grape/util/stackable_values.rb
|
385
|
+
- lib/grape/util/strict_hash_configuration.rb
|
363
386
|
- lib/grape/validations.rb
|
364
|
-
- lib/grape/validations/
|
365
|
-
- lib/grape/validations/
|
366
|
-
- lib/grape/validations/
|
367
|
-
- lib/grape/validations/
|
368
|
-
- lib/grape/validations/
|
369
|
-
- lib/grape/validations/
|
370
|
-
- lib/grape/validations/
|
371
|
-
- lib/grape/validations/
|
387
|
+
- lib/grape/validations/attributes_iterator.rb
|
388
|
+
- lib/grape/validations/params_scope.rb
|
389
|
+
- lib/grape/validations/validators/all_or_none.rb
|
390
|
+
- lib/grape/validations/validators/allow_blank.rb
|
391
|
+
- lib/grape/validations/validators/at_least_one_of.rb
|
392
|
+
- lib/grape/validations/validators/base.rb
|
393
|
+
- lib/grape/validations/validators/coerce.rb
|
394
|
+
- lib/grape/validations/validators/default.rb
|
395
|
+
- lib/grape/validations/validators/exactly_one_of.rb
|
396
|
+
- lib/grape/validations/validators/multiple_params_base.rb
|
397
|
+
- lib/grape/validations/validators/mutual_exclusion.rb
|
398
|
+
- lib/grape/validations/validators/presence.rb
|
399
|
+
- lib/grape/validations/validators/regexp.rb
|
400
|
+
- lib/grape/validations/validators/values.rb
|
372
401
|
- lib/grape/version.rb
|
373
402
|
- spec/grape/api/helpers_spec.rb
|
374
403
|
- spec/grape/api_spec.rb
|
@@ -380,6 +409,7 @@ files:
|
|
380
409
|
- spec/grape/dsl/parameters_spec.rb
|
381
410
|
- spec/grape/dsl/request_response_spec.rb
|
382
411
|
- spec/grape/dsl/routing_spec.rb
|
412
|
+
- spec/grape/dsl/settings_spec.rb
|
383
413
|
- spec/grape/dsl/validations_spec.rb
|
384
414
|
- spec/grape/endpoint_spec.rb
|
385
415
|
- spec/grape/entity_spec.rb
|
@@ -390,6 +420,7 @@ files:
|
|
390
420
|
- spec/grape/exceptions/unknown_options_spec.rb
|
391
421
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
392
422
|
- spec/grape/exceptions/validation_errors_spec.rb
|
423
|
+
- spec/grape/loading_spec.rb
|
393
424
|
- spec/grape/middleware/auth/base_spec.rb
|
394
425
|
- spec/grape/middleware/auth/dsl_spec.rb
|
395
426
|
- spec/grape/middleware/auth/strategies_spec.rb
|
@@ -403,16 +434,23 @@ files:
|
|
403
434
|
- spec/grape/middleware/versioner/path_spec.rb
|
404
435
|
- spec/grape/middleware/versioner_spec.rb
|
405
436
|
- spec/grape/path_spec.rb
|
406
|
-
- spec/grape/util/
|
407
|
-
- spec/grape/
|
408
|
-
- spec/grape/
|
409
|
-
- spec/grape/
|
410
|
-
- spec/grape/validations/
|
411
|
-
- spec/grape/validations/
|
412
|
-
- spec/grape/validations/
|
413
|
-
- spec/grape/validations/
|
414
|
-
- spec/grape/validations/
|
415
|
-
- spec/grape/validations/
|
437
|
+
- spec/grape/util/inheritable_setting_spec.rb
|
438
|
+
- spec/grape/util/inheritable_values_spec.rb
|
439
|
+
- spec/grape/util/stackable_values_spec.rb
|
440
|
+
- spec/grape/util/strict_hash_configuration_spec.rb
|
441
|
+
- spec/grape/validations/attributes_iterator_spec.rb
|
442
|
+
- spec/grape/validations/params_scope_spec.rb
|
443
|
+
- spec/grape/validations/validators/all_or_none_spec.rb
|
444
|
+
- spec/grape/validations/validators/allow_blank_spec.rb
|
445
|
+
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
446
|
+
- spec/grape/validations/validators/coerce_spec.rb
|
447
|
+
- spec/grape/validations/validators/default_spec.rb
|
448
|
+
- spec/grape/validations/validators/exactly_one_of_spec.rb
|
449
|
+
- spec/grape/validations/validators/mutual_exclusion_spec.rb
|
450
|
+
- spec/grape/validations/validators/presence_spec.rb
|
451
|
+
- spec/grape/validations/validators/regexp_spec.rb
|
452
|
+
- spec/grape/validations/validators/values_spec.rb
|
453
|
+
- spec/grape/validations/validators/zh-CN.yml
|
416
454
|
- spec/grape/validations_spec.rb
|
417
455
|
- spec/shared/versioning_examples.rb
|
418
456
|
- spec/spec_helper.rb
|
@@ -440,7 +478,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
440
478
|
version: '0'
|
441
479
|
requirements: []
|
442
480
|
rubyforge_project: grape
|
443
|
-
rubygems_version: 2.
|
481
|
+
rubygems_version: 2.2.2
|
444
482
|
signing_key:
|
445
483
|
specification_version: 4
|
446
484
|
summary: A simple Ruby framework for building REST-like APIs.
|
@@ -455,6 +493,7 @@ test_files:
|
|
455
493
|
- spec/grape/dsl/parameters_spec.rb
|
456
494
|
- spec/grape/dsl/request_response_spec.rb
|
457
495
|
- spec/grape/dsl/routing_spec.rb
|
496
|
+
- spec/grape/dsl/settings_spec.rb
|
458
497
|
- spec/grape/dsl/validations_spec.rb
|
459
498
|
- spec/grape/endpoint_spec.rb
|
460
499
|
- spec/grape/entity_spec.rb
|
@@ -465,6 +504,7 @@ test_files:
|
|
465
504
|
- spec/grape/exceptions/unknown_options_spec.rb
|
466
505
|
- spec/grape/exceptions/unknown_validator_spec.rb
|
467
506
|
- spec/grape/exceptions/validation_errors_spec.rb
|
507
|
+
- spec/grape/loading_spec.rb
|
468
508
|
- spec/grape/middleware/auth/base_spec.rb
|
469
509
|
- spec/grape/middleware/auth/dsl_spec.rb
|
470
510
|
- spec/grape/middleware/auth/strategies_spec.rb
|
@@ -478,16 +518,23 @@ test_files:
|
|
478
518
|
- spec/grape/middleware/versioner/path_spec.rb
|
479
519
|
- spec/grape/middleware/versioner_spec.rb
|
480
520
|
- spec/grape/path_spec.rb
|
481
|
-
- spec/grape/util/
|
482
|
-
- spec/grape/
|
483
|
-
- spec/grape/
|
484
|
-
- spec/grape/
|
485
|
-
- spec/grape/validations/
|
486
|
-
- spec/grape/validations/
|
487
|
-
- spec/grape/validations/
|
488
|
-
- spec/grape/validations/
|
489
|
-
- spec/grape/validations/
|
490
|
-
- spec/grape/validations/
|
521
|
+
- spec/grape/util/inheritable_setting_spec.rb
|
522
|
+
- spec/grape/util/inheritable_values_spec.rb
|
523
|
+
- spec/grape/util/stackable_values_spec.rb
|
524
|
+
- spec/grape/util/strict_hash_configuration_spec.rb
|
525
|
+
- spec/grape/validations/attributes_iterator_spec.rb
|
526
|
+
- spec/grape/validations/params_scope_spec.rb
|
527
|
+
- spec/grape/validations/validators/all_or_none_spec.rb
|
528
|
+
- spec/grape/validations/validators/allow_blank_spec.rb
|
529
|
+
- spec/grape/validations/validators/at_least_one_of_spec.rb
|
530
|
+
- spec/grape/validations/validators/coerce_spec.rb
|
531
|
+
- spec/grape/validations/validators/default_spec.rb
|
532
|
+
- spec/grape/validations/validators/exactly_one_of_spec.rb
|
533
|
+
- spec/grape/validations/validators/mutual_exclusion_spec.rb
|
534
|
+
- spec/grape/validations/validators/presence_spec.rb
|
535
|
+
- spec/grape/validations/validators/regexp_spec.rb
|
536
|
+
- spec/grape/validations/validators/values_spec.rb
|
537
|
+
- spec/grape/validations/validators/zh-CN.yml
|
491
538
|
- spec/grape/validations_spec.rb
|
492
539
|
- spec/shared/versioning_examples.rb
|
493
540
|
- spec/spec_helper.rb
|
@@ -1,23 +0,0 @@
|
|
1
|
-
class Hash
|
2
|
-
# deep_merge from rails
|
3
|
-
# activesupport/lib/active_support/core_ext/hash/deep_merge.rb
|
4
|
-
# Returns a new hash with +self+ and +other_hash+ merged recursively.
|
5
|
-
#
|
6
|
-
# h1 = {x: {y: [4,5,6]}, z: [7,8,9]}
|
7
|
-
# h2 = {x: {y: [7,8,9]}, z: "xyz"}
|
8
|
-
#
|
9
|
-
# h1.deep_merge(h2) #=> { x: {y: [7, 8, 9]}, z: "xyz" }
|
10
|
-
# h2.deep_merge(h1) #=> { x: {y: [4, 5, 6]}, z: [7, 8, 9] }
|
11
|
-
def deep_merge(other_hash)
|
12
|
-
dup.deep_merge!(other_hash)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Same as +deep_merge+, but modifies +self+.
|
16
|
-
def deep_merge!(other_hash)
|
17
|
-
other_hash.each_pair do |k, v|
|
18
|
-
tv = self[k]
|
19
|
-
self[k] = tv.is_a?(Hash) && v.is_a?(Hash) ? tv.deep_merge(v) : v
|
20
|
-
end
|
21
|
-
self
|
22
|
-
end
|
23
|
-
end
|
@@ -1,120 +0,0 @@
|
|
1
|
-
module Grape
|
2
|
-
module Util
|
3
|
-
# HashStack is a stack of hashes. When retrieving a value, keys of the top
|
4
|
-
# hash on the stack take precendent over the lower keys.
|
5
|
-
class HashStack
|
6
|
-
# Unmerged array of hashes to represent the stack.
|
7
|
-
# The top of the stack is the last element.
|
8
|
-
attr_reader :stack
|
9
|
-
|
10
|
-
# TODO: handle aggregates
|
11
|
-
def initialize
|
12
|
-
@stack = [{}]
|
13
|
-
end
|
14
|
-
|
15
|
-
# Returns the top hash on the stack
|
16
|
-
def peek
|
17
|
-
@stack.last
|
18
|
-
end
|
19
|
-
|
20
|
-
# Add a new hash to the top of the stack.
|
21
|
-
#
|
22
|
-
# @param hash [Hash] optional hash to be pushed. Defaults to empty hash
|
23
|
-
# @return [HashStack]
|
24
|
-
def push(hash = {})
|
25
|
-
@stack.push(hash)
|
26
|
-
self
|
27
|
-
end
|
28
|
-
|
29
|
-
def pop
|
30
|
-
@stack.pop
|
31
|
-
end
|
32
|
-
|
33
|
-
# Looks through the stack for the first frame that matches :key
|
34
|
-
#
|
35
|
-
# @param key [Symbol] key to look for in hash frames
|
36
|
-
# @return value of given key after merging the stack
|
37
|
-
def get(key)
|
38
|
-
(@stack.length - 1).downto(0).each do |i|
|
39
|
-
return @stack[i][key] if @stack[i].key? key
|
40
|
-
end
|
41
|
-
nil
|
42
|
-
end
|
43
|
-
alias_method :[], :get
|
44
|
-
|
45
|
-
# Looks through the stack for the first frame that matches :key
|
46
|
-
#
|
47
|
-
# @param key [Symbol] key to look for in hash frames
|
48
|
-
# @return true if key exists, false otherwise
|
49
|
-
def key?(key)
|
50
|
-
(@stack.length - 1).downto(0).each do |i|
|
51
|
-
return true if @stack[i].key? key
|
52
|
-
end
|
53
|
-
false
|
54
|
-
end
|
55
|
-
|
56
|
-
# Replace a value on the top hash of the stack.
|
57
|
-
#
|
58
|
-
# @param key [Symbol] The key to set.
|
59
|
-
# @param value [Object] The value to set.
|
60
|
-
def set(key, value)
|
61
|
-
peek[key.to_sym] = value
|
62
|
-
end
|
63
|
-
alias_method :[]=, :set
|
64
|
-
|
65
|
-
# Replace multiple values on the top hash of the stack.
|
66
|
-
#
|
67
|
-
# @param hash [Hash] Hash of values to be merged in.
|
68
|
-
def update(hash)
|
69
|
-
peek.merge!(hash)
|
70
|
-
self
|
71
|
-
end
|
72
|
-
|
73
|
-
# Adds addition value into the top hash of the stack
|
74
|
-
def imbue(key, value)
|
75
|
-
current = peek[key.to_sym]
|
76
|
-
if current.is_a?(Array)
|
77
|
-
current.concat(value)
|
78
|
-
elsif current.is_a?(Hash)
|
79
|
-
current.merge!(value)
|
80
|
-
else
|
81
|
-
set(key, value)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Prepend another HashStack's to self
|
86
|
-
def prepend(hash_stack)
|
87
|
-
@stack.unshift(*hash_stack.stack)
|
88
|
-
self
|
89
|
-
end
|
90
|
-
|
91
|
-
# Concatenate another HashStack's to self
|
92
|
-
def concat(hash_stack)
|
93
|
-
@stack.concat hash_stack.stack
|
94
|
-
self
|
95
|
-
end
|
96
|
-
|
97
|
-
# Looks through the stack for all instances of a given key and returns
|
98
|
-
# them as a flat Array.
|
99
|
-
#
|
100
|
-
# @param key [Symbol] The key to gather
|
101
|
-
# @return [Array]
|
102
|
-
def gather(key)
|
103
|
-
stack.flat_map { |s| s[key] }.compact.uniq
|
104
|
-
end
|
105
|
-
|
106
|
-
def to_s
|
107
|
-
@stack.to_s
|
108
|
-
end
|
109
|
-
|
110
|
-
def clone
|
111
|
-
new_stack = HashStack.new
|
112
|
-
stack.each do |frame|
|
113
|
-
new_stack.push frame.clone
|
114
|
-
end
|
115
|
-
new_stack.stack.shift
|
116
|
-
new_stack
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|