grape 0.13.0 → 0.14.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.

Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +9 -4
  3. data/CHANGELOG.md +28 -0
  4. data/Gemfile +0 -1
  5. data/Gemfile.lock +166 -0
  6. data/README.md +305 -163
  7. data/Rakefile +30 -33
  8. data/UPGRADING.md +31 -0
  9. data/benchmark/simple.rb +27 -0
  10. data/gemfiles/rack_1.5.2.gemfile +13 -0
  11. data/gemfiles/rails_3.gemfile +2 -2
  12. data/gemfiles/rails_4.gemfile +1 -2
  13. data/grape.gemspec +5 -4
  14. data/lib/grape.rb +9 -5
  15. data/lib/grape/dsl/configuration.rb +5 -2
  16. data/lib/grape/dsl/helpers.rb +8 -3
  17. data/lib/grape/dsl/inside_route.rb +67 -44
  18. data/lib/grape/dsl/parameters.rb +21 -12
  19. data/lib/grape/dsl/request_response.rb +1 -1
  20. data/lib/grape/dsl/routing.rb +3 -4
  21. data/lib/grape/endpoint.rb +63 -28
  22. data/lib/grape/error_formatter/base.rb +6 -6
  23. data/lib/grape/exceptions/base.rb +5 -5
  24. data/lib/grape/exceptions/invalid_version_header.rb +10 -0
  25. data/lib/grape/formatter/serializable_hash.rb +3 -2
  26. data/lib/grape/locale/en.yml +4 -1
  27. data/lib/grape/middleware/auth/base.rb +2 -2
  28. data/lib/grape/middleware/auth/dsl.rb +1 -1
  29. data/lib/grape/middleware/auth/strategies.rb +1 -1
  30. data/lib/grape/middleware/base.rb +7 -4
  31. data/lib/grape/middleware/error.rb +3 -2
  32. data/lib/grape/middleware/filter.rb +1 -1
  33. data/lib/grape/middleware/formatter.rb +47 -44
  34. data/lib/grape/middleware/globals.rb +3 -3
  35. data/lib/grape/middleware/versioner/accept_version_header.rb +5 -7
  36. data/lib/grape/middleware/versioner/header.rb +113 -50
  37. data/lib/grape/middleware/versioner/param.rb +5 -8
  38. data/lib/grape/middleware/versioner/parse_media_type_patch.rb +20 -0
  39. data/lib/grape/middleware/versioner/path.rb +3 -6
  40. data/lib/grape/path.rb +3 -3
  41. data/lib/grape/request.rb +40 -0
  42. data/lib/grape/util/content_types.rb +9 -9
  43. data/lib/grape/util/env.rb +22 -0
  44. data/lib/grape/util/strict_hash_configuration.rb +2 -1
  45. data/lib/grape/validations/attributes_iterator.rb +8 -3
  46. data/lib/grape/validations/params_scope.rb +83 -15
  47. data/lib/grape/validations/types.rb +144 -0
  48. data/lib/grape/validations/types/build_coercer.rb +53 -0
  49. data/lib/grape/validations/types/custom_type_coercer.rb +183 -0
  50. data/lib/grape/validations/types/file.rb +28 -0
  51. data/lib/grape/validations/types/json.rb +65 -0
  52. data/lib/grape/validations/types/multiple_type_coercer.rb +76 -0
  53. data/lib/grape/validations/types/variant_collection_coercer.rb +59 -0
  54. data/lib/grape/validations/types/virtus_collection_patch.rb +16 -0
  55. data/lib/grape/validations/validators/all_or_none.rb +1 -1
  56. data/lib/grape/validations/validators/allow_blank.rb +3 -3
  57. data/lib/grape/validations/validators/base.rb +7 -0
  58. data/lib/grape/validations/validators/coerce.rb +31 -42
  59. data/lib/grape/validations/validators/presence.rb +2 -3
  60. data/lib/grape/validations/validators/regexp.rb +2 -4
  61. data/lib/grape/validations/validators/values.rb +3 -3
  62. data/lib/grape/version.rb +1 -1
  63. data/pkg/grape-0.13.0.gem +0 -0
  64. data/spec/grape/api/custom_validations_spec.rb +5 -4
  65. data/spec/grape/api/deeply_included_options_spec.rb +7 -7
  66. data/spec/grape/api/nested_helpers_spec.rb +4 -2
  67. data/spec/grape/api/shared_helpers_spec.rb +8 -8
  68. data/spec/grape/api_spec.rb +88 -54
  69. data/spec/grape/dsl/configuration_spec.rb +13 -0
  70. data/spec/grape/dsl/helpers_spec.rb +16 -2
  71. data/spec/grape/dsl/inside_route_spec.rb +3 -2
  72. data/spec/grape/dsl/parameters_spec.rb +0 -6
  73. data/spec/grape/dsl/routing_spec.rb +1 -1
  74. data/spec/grape/endpoint_spec.rb +61 -20
  75. data/spec/grape/entity_spec.rb +10 -8
  76. data/spec/grape/exceptions/invalid_accept_header_spec.rb +1 -15
  77. data/spec/grape/integration/rack_spec.rb +3 -2
  78. data/spec/grape/middleware/base_spec.rb +7 -5
  79. data/spec/grape/middleware/error_spec.rb +16 -15
  80. data/spec/grape/middleware/exception_spec.rb +45 -43
  81. data/spec/grape/middleware/formatter_spec.rb +34 -0
  82. data/spec/grape/middleware/versioner/header_spec.rb +79 -47
  83. data/spec/grape/path_spec.rb +10 -10
  84. data/spec/grape/presenters/presenter_spec.rb +2 -2
  85. data/spec/grape/request_spec.rb +100 -0
  86. data/spec/grape/validations/params_scope_spec.rb +11 -9
  87. data/spec/grape/validations/types_spec.rb +95 -0
  88. data/spec/grape/validations/validators/coerce_spec.rb +335 -2
  89. data/spec/grape/validations/validators/values_spec.rb +15 -15
  90. data/spec/grape/validations_spec.rb +53 -24
  91. data/spec/shared/versioning_examples.rb +2 -2
  92. data/spec/spec_helper.rb +0 -1
  93. data/spec/support/versioned_helpers.rb +2 -2
  94. metadata +51 -13
  95. data/.gitignore +0 -46
  96. data/.rspec +0 -2
  97. data/.rubocop.yml +0 -7
  98. data/.rubocop_todo.yml +0 -84
  99. data/.travis.yml +0 -20
  100. data/.yardopts +0 -2
  101. data/lib/grape/http/request.rb +0 -35
  102. data/lib/grape/util/parameter_types.rb +0 -58
  103. data/spec/grape/util/parameter_types_spec.rb +0 -54
data/.gitignore DELETED
@@ -1,46 +0,0 @@
1
- ## MAC OS
2
- .DS_Store
3
- .com.apple.timemachine.supported
4
-
5
- ## TEXTMATE
6
- *.tmproj
7
- tmtags
8
-
9
- ## EMACS
10
- *~
11
- \#*
12
- .\#*
13
-
14
- ## REDCAR
15
- .redcar
16
-
17
- ## VIM
18
- *.swp
19
- *.swo
20
-
21
- ## RUBYMINE
22
- .idea
23
-
24
- ## PROJECT::GENERAL
25
- coverage
26
- doc
27
- pkg
28
- .rvmrc
29
- .bundle
30
- .yardoc/*
31
- dist
32
- Gemfile.lock
33
- gemfiles/*.lock
34
- tmp
35
-
36
- ## Rubinius
37
- .rbx
38
-
39
- ## Bundler binstubs
40
- bin
41
-
42
- ## ripper-tags and gem-ctags
43
- tags
44
-
45
- ## PROJECT::SPECIFIC
46
- .project
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --format=documentation
@@ -1,7 +0,0 @@
1
- AllCops:
2
- Exclude:
3
- - vendor/**/*
4
- - bin/**/*
5
- - gemfiles/**/*
6
-
7
- inherit_from: .rubocop_todo.yml
@@ -1,84 +0,0 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`
2
- # on 2015-06-04 09:15:17 -0400 using RuboCop version 0.31.0.
3
- # The point is for the user to remove these configuration records
4
- # one by one as the offenses are removed from the code base.
5
- # Note that changes in the inspected code, or installation of new
6
- # versions of RuboCop, may require this file to be generated again.
7
-
8
- # Offense count: 37
9
- Metrics/AbcSize:
10
- Max: 48
11
-
12
- # Offense count: 2
13
- Metrics/BlockNesting:
14
- Max: 4
15
-
16
- # Offense count: 4
17
- # Configuration parameters: CountComments.
18
- Metrics/ClassLength:
19
- Max: 252
20
-
21
- # Offense count: 23
22
- Metrics/CyclomaticComplexity:
23
- Max: 20
24
-
25
- # Offense count: 675
26
- # Configuration parameters: AllowURI, URISchemes.
27
- Metrics/LineLength:
28
- Max: 198
29
-
30
- # Offense count: 44
31
- # Configuration parameters: CountComments.
32
- Metrics/MethodLength:
33
- Max: 35
34
-
35
- # Offense count: 8
36
- # Configuration parameters: CountComments.
37
- Metrics/ModuleLength:
38
- Max: 271
39
-
40
- # Offense count: 17
41
- Metrics/PerceivedComplexity:
42
- Max: 22
43
-
44
- # Offense count: 26
45
- # Cop supports --auto-correct.
46
- # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
47
- Style/BlockDelimiters:
48
- Enabled: false
49
-
50
- # Offense count: 174
51
- Style/Documentation:
52
- Enabled: false
53
-
54
- # Offense count: 7
55
- Style/DoubleNegation:
56
- Enabled: false
57
-
58
- # Offense count: 5
59
- Style/EachWithObject:
60
- Enabled: false
61
-
62
- # Offense count: 15
63
- # Configuration parameters: MinBodyLength.
64
- Style/GuardClause:
65
- Enabled: false
66
-
67
- # Offense count: 4
68
- # Cop supports --auto-correct.
69
- Style/Lambda:
70
- Enabled: false
71
-
72
- # Offense count: 3
73
- Style/MultilineTernaryOperator:
74
- Enabled: false
75
-
76
- # Offense count: 3
77
- # Configuration parameters: NamePrefix, NamePrefixBlacklist.
78
- Style/PredicateName:
79
- Enabled: false
80
-
81
- # Offense count: 13
82
- # Configuration parameters: EnforcedStyle, SupportedStyles.
83
- Style/RaiseArgs:
84
- Enabled: false
@@ -1,20 +0,0 @@
1
- language: ruby
2
-
3
- rvm:
4
- - 2.2
5
- - 2.1
6
- - 2.0.0
7
- - rbx-2.2.10
8
- - jruby-19mode
9
- - ruby-head
10
- - jruby-head
11
-
12
- matrix:
13
- allow_failures:
14
- - rvm: ruby-head
15
- - rvm: jruby-head
16
-
17
- gemfile:
18
- - Gemfile
19
- - gemfiles/rails_3.gemfile
20
- - gemfiles/rails_4.gemfile
data/.yardopts DELETED
@@ -1,2 +0,0 @@
1
- --markup-provider=redcarpet
2
- --markup=markdown
@@ -1,35 +0,0 @@
1
- module Grape
2
- class Request < Rack::Request
3
- ROUTING_ARGS = 'rack.routing_args'
4
- HTTP_PREFIX = 'HTTP_'
5
- UNDERSCORE = '_'
6
- MINUS = '-'
7
-
8
- def params
9
- @params ||= begin
10
- params = Hashie::Mash.new(super)
11
- if env[ROUTING_ARGS]
12
- args = env[ROUTING_ARGS].dup
13
- # preserve version from query string parameters
14
- args.delete(:version)
15
- args.delete(:route_info)
16
- params.deep_merge!(args)
17
- end
18
- params
19
- end
20
- end
21
-
22
- def headers
23
- @headers ||= env.dup.inject({}) do |h, (k, v)|
24
- if k.to_s.start_with? HTTP_PREFIX
25
- k = k[5..-1]
26
- k.tr!(UNDERSCORE, MINUS)
27
- k.downcase!
28
- k.gsub!(/^.|[-_\s]./, &:upcase!)
29
- h[k] = v
30
- end
31
- h
32
- end
33
- end
34
- end
35
- end
@@ -1,58 +0,0 @@
1
- module Grape
2
- module ParameterTypes
3
- # Types representing a single value, which are coerced through Virtus
4
- # or special logic in Grape.
5
- PRIMITIVES = [
6
- # Numerical
7
- Integer,
8
- Float,
9
- BigDecimal,
10
- Numeric,
11
-
12
- # Date/time
13
- Date,
14
- DateTime,
15
- Time,
16
-
17
- # Misc
18
- Virtus::Attribute::Boolean,
19
- String,
20
- Symbol,
21
- Rack::Multipart::UploadedFile
22
- ]
23
-
24
- # Types representing data structures.
25
- STRUCTURES = [
26
- Hash,
27
- Array,
28
- Set
29
- ]
30
-
31
- # @param type [Class] type to check
32
- # @return [Boolean] whether or not the type is known by Grape as a valid
33
- # type for a single value
34
- def self.primitive?(type)
35
- PRIMITIVES.include?(type)
36
- end
37
-
38
- # @param type [Class] type to check
39
- # @return [Boolean] whether or not the type is known by Grape as a valid
40
- # data structure type
41
- # @note This method does not yet consider 'complex types', which inherit
42
- # Virtus.model.
43
- def self.structure?(type)
44
- STRUCTURES.include?(type)
45
- end
46
-
47
- # A valid custom type must implement a class-level `parse` method, taking
48
- # one String argument and returning the parsed value in its correct type.
49
- # @param type [Class] type to check
50
- # @return [Boolean] whether or not the type can be used as a custom type
51
- def self.custom_type?(type)
52
- !primitive?(type) &&
53
- !structure?(type) &&
54
- type.respond_to?(:parse) &&
55
- type.method(:parse).arity == 1
56
- end
57
- end
58
- end
@@ -1,54 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Grape::ParameterTypes do
4
- class FooType
5
- def self.parse(_)
6
- end
7
- end
8
-
9
- class BarType
10
- def self.parse
11
- end
12
- end
13
-
14
- describe '::primitive?' do
15
- [
16
- Integer, Float, Numeric, BigDecimal,
17
- Virtus::Attribute::Boolean, String, Symbol,
18
- Date, DateTime, Time, Rack::Multipart::UploadedFile
19
- ].each do |type|
20
- it "recognizes #{type} as a primitive" do
21
- expect(described_class.primitive?(type)).to be_truthy
22
- end
23
- end
24
-
25
- it 'identifies unknown types' do
26
- expect(described_class.primitive?(Object)).to be_falsy
27
- expect(described_class.primitive?(FooType)).to be_falsy
28
- end
29
- end
30
-
31
- describe '::structure?' do
32
- [
33
- Hash, Array, Set
34
- ].each do |type|
35
- it "recognizes #{type} as a structure" do
36
- expect(described_class.structure?(type)).to be_truthy
37
- end
38
- end
39
- end
40
-
41
- describe '::custom_type?' do
42
- it 'returns false if the type does not respond to :parse' do
43
- expect(described_class.custom_type?(Object)).to be_falsy
44
- end
45
-
46
- it 'returns true if the type responds to :parse with one argument' do
47
- expect(described_class.custom_type?(FooType)).to be_truthy
48
- end
49
-
50
- it 'returns false if the type\'s #parse method takes other than one argument' do
51
- expect(described_class.custom_type?(BarType)).to be_falsy
52
- end
53
- end
54
- end