grape 0.3.0 → 0.7.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 (101) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +8 -0
  3. data/.rubocop.yml +70 -0
  4. data/.travis.yml +7 -6
  5. data/CHANGELOG.md +134 -4
  6. data/CONTRIBUTING.md +118 -0
  7. data/Gemfile +5 -2
  8. data/README.md +551 -116
  9. data/RELEASING.md +105 -0
  10. data/Rakefile +29 -8
  11. data/UPGRADING.md +124 -0
  12. data/grape.gemspec +3 -3
  13. data/lib/grape/api.rb +207 -88
  14. data/lib/grape/cookies.rb +4 -8
  15. data/lib/grape/endpoint.rb +198 -144
  16. data/lib/grape/error_formatter/base.rb +5 -7
  17. data/lib/grape/error_formatter/json.rb +3 -5
  18. data/lib/grape/error_formatter/txt.rb +1 -3
  19. data/lib/grape/error_formatter/xml.rb +4 -6
  20. data/lib/grape/exceptions/base.rb +9 -9
  21. data/lib/grape/exceptions/incompatible_option_values.rb +10 -0
  22. data/lib/grape/exceptions/invalid_formatter.rb +1 -4
  23. data/lib/grape/exceptions/invalid_versioner_option.rb +1 -5
  24. data/lib/grape/exceptions/invalid_with_option_for_represent.rb +1 -6
  25. data/lib/grape/exceptions/missing_mime_type.rb +1 -5
  26. data/lib/grape/exceptions/missing_option.rb +1 -4
  27. data/lib/grape/exceptions/missing_vendor_option.rb +1 -4
  28. data/lib/grape/exceptions/unknown_options.rb +1 -5
  29. data/lib/grape/exceptions/unknown_validator.rb +1 -3
  30. data/lib/grape/exceptions/validation.rb +13 -3
  31. data/lib/grape/exceptions/validation_errors.rb +43 -0
  32. data/lib/grape/formatter/base.rb +5 -7
  33. data/lib/grape/formatter/json.rb +0 -3
  34. data/lib/grape/formatter/serializable_hash.rb +15 -15
  35. data/lib/grape/formatter/txt.rb +0 -2
  36. data/lib/grape/formatter/xml.rb +0 -2
  37. data/lib/grape/http/request.rb +26 -0
  38. data/lib/grape/locale/en.yml +8 -5
  39. data/lib/grape/middleware/auth/base.rb +30 -0
  40. data/lib/grape/middleware/auth/basic.rb +3 -20
  41. data/lib/grape/middleware/auth/digest.rb +2 -19
  42. data/lib/grape/middleware/auth/oauth2.rb +31 -24
  43. data/lib/grape/middleware/base.rb +7 -7
  44. data/lib/grape/middleware/error.rb +36 -22
  45. data/lib/grape/middleware/filter.rb +3 -3
  46. data/lib/grape/middleware/formatter.rb +99 -61
  47. data/lib/grape/middleware/globals.rb +13 -0
  48. data/lib/grape/middleware/versioner/accept_version_header.rb +67 -0
  49. data/lib/grape/middleware/versioner/header.rb +22 -16
  50. data/lib/grape/middleware/versioner/param.rb +9 -11
  51. data/lib/grape/middleware/versioner/path.rb +10 -13
  52. data/lib/grape/middleware/versioner.rb +3 -1
  53. data/lib/grape/namespace.rb +23 -0
  54. data/lib/grape/parser/base.rb +3 -5
  55. data/lib/grape/parser/json.rb +0 -2
  56. data/lib/grape/parser/xml.rb +0 -2
  57. data/lib/grape/path.rb +70 -0
  58. data/lib/grape/route.rb +10 -6
  59. data/lib/grape/util/content_types.rb +2 -1
  60. data/lib/grape/util/deep_merge.rb +5 -5
  61. data/lib/grape/util/hash_stack.rb +13 -2
  62. data/lib/grape/validations/coerce.rb +11 -10
  63. data/lib/grape/validations/default.rb +25 -0
  64. data/lib/grape/validations/presence.rb +7 -3
  65. data/lib/grape/validations/regexp.rb +2 -5
  66. data/lib/grape/validations/values.rb +17 -0
  67. data/lib/grape/validations.rb +161 -54
  68. data/lib/grape/version.rb +1 -1
  69. data/lib/grape.rb +19 -4
  70. data/spec/grape/api_spec.rb +897 -268
  71. data/spec/grape/endpoint_spec.rb +283 -66
  72. data/spec/grape/entity_spec.rb +132 -29
  73. data/spec/grape/exceptions/missing_mime_type_spec.rb +3 -9
  74. data/spec/grape/exceptions/validation_errors_spec.rb +19 -0
  75. data/spec/grape/middleware/auth/basic_spec.rb +8 -8
  76. data/spec/grape/middleware/auth/digest_spec.rb +5 -5
  77. data/spec/grape/middleware/auth/oauth2_spec.rb +81 -36
  78. data/spec/grape/middleware/base_spec.rb +8 -13
  79. data/spec/grape/middleware/error_spec.rb +13 -17
  80. data/spec/grape/middleware/exception_spec.rb +47 -27
  81. data/spec/grape/middleware/formatter_spec.rb +103 -41
  82. data/spec/grape/middleware/versioner/accept_version_header_spec.rb +121 -0
  83. data/spec/grape/middleware/versioner/header_spec.rb +76 -51
  84. data/spec/grape/middleware/versioner/param_spec.rb +18 -18
  85. data/spec/grape/middleware/versioner/path_spec.rb +6 -6
  86. data/spec/grape/middleware/versioner_spec.rb +5 -2
  87. data/spec/grape/path_spec.rb +229 -0
  88. data/spec/grape/util/hash_stack_spec.rb +31 -32
  89. data/spec/grape/validations/coerce_spec.rb +116 -51
  90. data/spec/grape/validations/default_spec.rb +123 -0
  91. data/spec/grape/validations/presence_spec.rb +42 -44
  92. data/spec/grape/validations/regexp_spec.rb +9 -9
  93. data/spec/grape/validations/values_spec.rb +138 -0
  94. data/spec/grape/validations/zh-CN.yml +4 -3
  95. data/spec/grape/validations_spec.rb +681 -48
  96. data/spec/shared/versioning_examples.rb +22 -6
  97. data/spec/spec_helper.rb +3 -2
  98. data/spec/support/basic_auth_encode_helpers.rb +0 -1
  99. data/spec/support/content_type_helpers.rb +11 -0
  100. data/spec/support/versioned_helpers.rb +13 -5
  101. metadata +34 -84
data/lib/grape.rb CHANGED
@@ -6,26 +6,38 @@ require 'rack/accept'
6
6
  require 'rack/auth/basic'
7
7
  require 'rack/auth/digest/md5'
8
8
  require 'hashie'
9
- require 'active_support/all'
9
+ require 'set'
10
+ require 'active_support/core_ext/hash/indifferent_access'
11
+ require 'active_support/ordered_hash'
12
+ require 'active_support/core_ext/object/conversions'
13
+ require 'active_support/core_ext/array/extract_options'
10
14
  require 'grape/util/deep_merge'
11
15
  require 'grape/util/content_types'
12
16
  require 'multi_json'
13
17
  require 'multi_xml'
14
18
  require 'virtus'
15
19
  require 'i18n'
20
+ require 'thread'
16
21
 
17
22
  I18n.load_path << File.expand_path('../grape/locale/en.yml', __FILE__)
18
23
 
19
24
  module Grape
20
25
  autoload :API, 'grape/api'
21
26
  autoload :Endpoint, 'grape/endpoint'
27
+
22
28
  autoload :Route, 'grape/route'
29
+ autoload :Namespace, 'grape/namespace'
30
+
31
+ autoload :Path, 'grape/path'
32
+
23
33
  autoload :Cookies, 'grape/cookies'
24
34
  autoload :Validations, 'grape/validations'
35
+ autoload :Request, 'grape/http/request'
25
36
 
26
37
  module Exceptions
27
38
  autoload :Base, 'grape/exceptions/base'
28
39
  autoload :Validation, 'grape/exceptions/validation'
40
+ autoload :ValidationErrors, 'grape/exceptions/validation_errors'
29
41
  autoload :MissingVendorOption, 'grape/exceptions/missing_vendor_option'
30
42
  autoload :MissingMimeType, 'grape/exceptions/missing_mime_type'
31
43
  autoload :MissingOption, 'grape/exceptions/missing_option'
@@ -34,6 +46,7 @@ module Grape
34
46
  autoload :UnknownValidator, 'grape/exceptions/unknown_validator'
35
47
  autoload :UnknownOptions, 'grape/exceptions/unknown_options'
36
48
  autoload :InvalidWithOptionForRepresent, 'grape/exceptions/invalid_with_option_for_represent'
49
+ autoload :IncompatibleOptionValues, 'grape/exceptions/incompatible_option_values'
37
50
  end
38
51
 
39
52
  module ErrorFormatter
@@ -65,14 +78,16 @@ module Grape
65
78
 
66
79
  module Auth
67
80
  autoload :OAuth2, 'grape/middleware/auth/oauth2'
81
+ autoload :Base, 'grape/middleware/auth/base'
68
82
  autoload :Basic, 'grape/middleware/auth/basic'
69
83
  autoload :Digest, 'grape/middleware/auth/digest'
70
84
  end
71
85
 
72
86
  module Versioner
73
- autoload :Path, 'grape/middleware/versioner/path'
74
- autoload :Header, 'grape/middleware/versioner/header'
75
- autoload :Param, 'grape/middleware/versioner/param'
87
+ autoload :Path, 'grape/middleware/versioner/path'
88
+ autoload :Header, 'grape/middleware/versioner/header'
89
+ autoload :Param, 'grape/middleware/versioner/param'
90
+ autoload :AcceptVersionHeader, 'grape/middleware/versioner/accept_version_header'
76
91
  end
77
92
  end
78
93