grape 0.19.2 → 1.0.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 (73) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +8 -0
  3. data/CHANGELOG.md +40 -22
  4. data/Gemfile +1 -0
  5. data/Gemfile.lock +58 -59
  6. data/LICENSE +1 -1
  7. data/README.md +94 -49
  8. data/Rakefile +1 -0
  9. data/UPGRADING.md +89 -0
  10. data/benchmark/simple_with_type_coercer.rb +22 -0
  11. data/gemfiles/multi_json.gemfile +36 -0
  12. data/gemfiles/multi_xml.gemfile +36 -0
  13. data/gemfiles/rack_1.5.2.gemfile +1 -0
  14. data/gemfiles/rack_edge.gemfile +1 -0
  15. data/gemfiles/rails_3.gemfile +1 -0
  16. data/gemfiles/rails_4.gemfile +1 -0
  17. data/gemfiles/rails_5.gemfile +1 -0
  18. data/gemfiles/rails_edge.gemfile +1 -0
  19. data/grape.gemspec +0 -3
  20. data/lib/grape.rb +40 -17
  21. data/lib/grape/dsl/helpers.rb +32 -18
  22. data/lib/grape/dsl/inside_route.rb +2 -2
  23. data/lib/grape/dsl/parameters.rb +26 -0
  24. data/lib/grape/dsl/routing.rb +1 -1
  25. data/lib/grape/dsl/settings.rb +1 -1
  26. data/lib/grape/endpoint.rb +20 -16
  27. data/lib/grape/error_formatter/json.rb +1 -1
  28. data/lib/grape/error_formatter/txt.rb +1 -1
  29. data/lib/grape/extensions/active_support/hash_with_indifferent_access.rb +26 -0
  30. data/lib/grape/extensions/deep_hash_with_indifferent_access.rb +18 -0
  31. data/lib/grape/extensions/deep_mergeable_hash.rb +19 -0
  32. data/lib/grape/extensions/deep_symbolize_hash.rb +30 -0
  33. data/lib/grape/extensions/hash.rb +23 -0
  34. data/lib/grape/extensions/hashie/mash.rb +24 -0
  35. data/lib/grape/formatter/json.rb +1 -1
  36. data/lib/grape/formatter/serializable_hash.rb +2 -2
  37. data/lib/grape/locale/en.yml +1 -1
  38. data/lib/grape/middleware/globals.rb +1 -1
  39. data/lib/grape/parser/json.rb +2 -2
  40. data/lib/grape/parser/xml.rb +2 -2
  41. data/lib/grape/request.rb +11 -10
  42. data/lib/grape/util/json.rb +8 -0
  43. data/lib/grape/util/xml.rb +8 -0
  44. data/lib/grape/validations.rb +4 -0
  45. data/lib/grape/validations/params_scope.rb +77 -39
  46. data/lib/grape/validations/types/build_coercer.rb +27 -0
  47. data/lib/grape/validations/types/custom_type_coercer.rb +18 -4
  48. data/lib/grape/validations/types/file.rb +2 -3
  49. data/lib/grape/validations/validator_factory.rb +18 -0
  50. data/lib/grape/validations/validators/base.rb +4 -5
  51. data/lib/grape/validations/validators/coerce.rb +4 -0
  52. data/lib/grape/validations/validators/except_values.rb +20 -0
  53. data/lib/grape/validations/validators/values.rb +25 -5
  54. data/lib/grape/version.rb +1 -1
  55. data/spec/grape/api/invalid_format_spec.rb +3 -3
  56. data/spec/grape/api_spec.rb +28 -16
  57. data/spec/grape/dsl/helpers_spec.rb +25 -6
  58. data/spec/grape/endpoint_spec.rb +117 -13
  59. data/spec/grape/extensions/param_builders/hash_spec.rb +83 -0
  60. data/spec/grape/extensions/param_builders/hash_with_indifferent_access_spec.rb +105 -0
  61. data/spec/grape/extensions/param_builders/hashie/mash_spec.rb +79 -0
  62. data/spec/grape/middleware/formatter_spec.rb +6 -2
  63. data/spec/grape/request_spec.rb +13 -3
  64. data/spec/grape/validations/instance_behaivour_spec.rb +44 -0
  65. data/spec/grape/validations/params_scope_spec.rb +23 -0
  66. data/spec/grape/validations/types_spec.rb +19 -0
  67. data/spec/grape/validations/validators/coerce_spec.rb +117 -8
  68. data/spec/grape/validations/validators/except_values_spec.rb +191 -0
  69. data/spec/grape/validations/validators/values_spec.rb +78 -0
  70. data/spec/integration/multi_json/json_spec.rb +7 -0
  71. data/spec/integration/multi_xml/xml_spec.rb +7 -0
  72. metadata +30 -46
  73. data/pkg/grape-0.18.0.gem +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ba880f34333ebf1f118e85d3abed4f9865cbd93e
4
- data.tar.gz: 3e7bc61918013dfa379825b2b1cba9153d36ee7d
3
+ metadata.gz: d283d4483281266120c9894d4abf116577e4f6d0
4
+ data.tar.gz: d730405b71975b6d471a9fd0366bc49715377725
5
5
  SHA512:
6
- metadata.gz: 85064ad017499b0e385a9fefc63664dc41ebdaf1d23f7fa9fe3a323a1143775f9f022159162297103e74925838045589abc75f972eb7e36f1d269c1a19f7d568
7
- data.tar.gz: 8b6b07647b936108df041c67cdf3ce0141873263b2af13ddc20e7b880ed747f687313c6bf4279c7de86098cdf87ca5acf5389e0e3363c75a9cb46a9ce5e2d9f9
6
+ metadata.gz: 134c53c62b330e7ff63acb341d30ae493b303d29610d57a8746796533698e9c83addbee84836440a921240f3a38451139e3699ec3f273cfb2eaeabdb162c1560
7
+ data.tar.gz: dd02f3635d42061cdfe7ee32984541c0284f39c38c38b3e541b409ba64af66cfd9f691c400c68ff899d42e387784a25e08eb8176e462c04995b3f8b55363d180
data/Appraisals CHANGED
@@ -22,3 +22,11 @@ end
22
22
  appraise 'rack-edge' do
23
23
  gem 'rack', github: 'rack/rack'
24
24
  end
25
+
26
+ appraise 'multi_json' do
27
+ gem 'multi_json', require: 'multi_json'
28
+ end
29
+
30
+ appraise 'multi_xml' do
31
+ gem 'multi_xml', require: 'multi_xml'
32
+ end
@@ -1,3 +1,22 @@
1
+ ### 1.0.0 (7/3/2017)
2
+
3
+ #### Features
4
+
5
+ * [#1594](https://github.com/ruby-grape/grape/pull/1594): Replace `Hashie::Mash` parameters with `ActiveSupport::HashWithIndifferentAccess` - [@james2m](https://github.com/james2m), [@dblock](https://github.com/dblock).
6
+ * [#1622](https://github.com/ruby-grape/grape/pull/1622): Add `except_values` validator to replace `except` option of `values` validator - [@jlfaber](https://github.com/jlfaber).
7
+ * [#1635](https://github.com/ruby-grape/grape/pull/1635): Instrument validators with ActiveSupport::Notifications - [@ktimothy](https://github.com/ktimothy).
8
+ * [#1646](https://github.com/ruby-grape/grape/pull/1646): Add ability to include an array of modules as helpers - [@pablonahuelgomez](https://github.com/pablonahuelgomez).
9
+ * [#1623](https://github.com/ruby-grape/grape/pull/1623): Removed `multi_json` and `multi_xml` dependencies - [@dblock](https://github.com/dblock).
10
+ * [#1650](https://github.com/ruby-grape/grape/pull/1650): Add extra specs for Boolean type field - [@tiarly](https://github.com/tiarly).
11
+
12
+ #### Fixes
13
+
14
+ * [#1648](https://github.com/ruby-grape/grape/pull/1631): Declared now returns declared options using the class that params is set to use - [@thogg4](https://github.com/thogg4).
15
+ * [#1632](https://github.com/ruby-grape/grape/pull/1632): Silence warnings - [@thogg4](https://github.com/thogg4).
16
+ * [#1615](https://github.com/ruby-grape/grape/pull/1615): Fix default and type validator when values is a Hash with no value attribute - [@jlfaber](https://github.com/jlfaber).
17
+ * [#1625](https://github.com/ruby-grape/grape/pull/1625): Handle `given` correctly when nested in Array params - [@rnubel](https://github.com/rnubel), [@avellable](https://github.com/avellable).
18
+ * [#1649](https://github.com/ruby-grape/grape/pull/1649): Don't share validator instances between requests - [@anakinj](https://github.com/anakinj).
19
+
1
20
  ### 0.19.2 (4/12/2017)
2
21
 
3
22
  #### Features
@@ -23,21 +42,21 @@
23
42
 
24
43
  #### Features
25
44
 
26
- * [#1536](https://github.com/ruby-grape/grape/pull/1536): Updates `invalid_versioner_option` translation - [@Lavode](https://github.com/Lavode).
27
- * [#1543](https://github.com/ruby-grape/grape/pull/1543): Support ruby 2.4 - [@LeFnord](https://github.com/LeFnord), [@namusyaka](https://github.com/namusyaka).
45
+ * [#1536](https://github.com/ruby-grape/grape/pull/1536): Updated `invalid_versioner_option` translation - [@Lavode](https://github.com/Lavode).
46
+ * [#1543](https://github.com/ruby-grape/grape/pull/1543): Added support for ruby 2.4 - [@LeFnord](https://github.com/LeFnord), [@namusyaka](https://github.com/namusyaka).
28
47
 
29
48
  #### Fixes
30
49
 
31
- * [#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).
32
- * [#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).
50
+ * [#1548](https://github.com/ruby-grape/grape/pull/1548): Fix: avoid failing even if given path does not match with prefix - [@thomas-peyric](https://github.com/thomas-peyric), [@namusyaka](https://github.com/namusyaka).
51
+ * [#1550](https://github.com/ruby-grape/grape/pull/1550): Fix: return 200 as default status for DELETE - [@jthornec](https://github.com/jthornec).
33
52
 
34
53
  ### 0.19.0 (12/18/2016)
35
54
 
36
55
  #### Features
37
56
 
38
- * [#1503](https://github.com/ruby-grape/grape/pull/1503): Allow to use regexp validator with arrays - [@akoltun](https://github.com/akoltun).
39
- * [#1507](https://github.com/ruby-grape/grape/pull/1507): Add group attributes for parameter definitions - [@304](https://github.com/304).
40
- * [#1532](https://github.com/ruby-grape/grape/pull/1532): Sets 204 as default status for delete - [@LeFnord](https://github.com/LeFnord).
57
+ * [#1503](https://github.com/ruby-grape/grape/pull/1503): Allowed use of regexp validator with arrays - [@akoltun](https://github.com/akoltun).
58
+ * [#1507](https://github.com/ruby-grape/grape/pull/1507): Added group attributes for parameter definitions - [@304](https://github.com/304).
59
+ * [#1532](https://github.com/ruby-grape/grape/pull/1532): Set 204 as default status for DELETE - [@LeFnord](https://github.com/LeFnord).
41
60
 
42
61
  #### Fixes
43
62
 
@@ -45,36 +64,35 @@
45
64
  * [#1517](https://github.com/ruby-grape/grape/pull/1517), [#1089](https://github.com/ruby-grape/grape/pull/1089): Fix: priority of ANY routes - [@namusyaka](https://github.com/namusyaka), [@wagenet](https://github.com/wagenet).
46
65
  * [#1512](https://github.com/ruby-grape/grape/pull/1512): Fix: deeply nested parameters are included within `#declared(params)` - [@krbs](https://github.com/krbs).
47
66
  * [#1510](https://github.com/ruby-grape/grape/pull/1510): Fix: inconsistent validation for multiple parameters - [@dgasper](https://github.com/dgasper).
48
- * [#1526](https://github.com/ruby-grape/grape/pull/1526): Reduce warnings caused by instance variables not initialized - [@cpetschnig](https://github.com/cpetschnig).
49
- * [#1531](https://github.com/ruby-grape/grape/pull/1531): Updates gem dependencies - [@LeFnord](https://github.com/LeFnord).
67
+ * [#1526](https://github.com/ruby-grape/grape/pull/1526): Reduced warnings caused by instance variables not initialized - [@cpetschnig](https://github.com/cpetschnig).
50
68
 
51
69
  ### 0.18.0 (10/7/2016)
52
70
 
53
71
  #### Features
54
72
 
55
- * [#1480](https://github.com/ruby-grape/grape/pull/1480): Use the ruby-grape-danger gem for PR linting - [@dblock](https://github.com/dblock).
73
+ * [#1480](https://github.com/ruby-grape/grape/pull/1480): Used the ruby-grape-danger gem for PR linting - [@dblock](https://github.com/dblock).
56
74
  * [#1486](https://github.com/ruby-grape/grape/pull/1486): Implemented except in values validator - [@jonmchan](https://github.com/jonmchan).
57
- * [#1470](https://github.com/ruby-grape/grape/pull/1470): Drop support for ruby-2.0 - [@namusyaka](https://github.com/namusyaka).
58
- * [#1490](https://github.com/ruby-grape/grape/pull/1490): Switch to Ruby-2.x+ syntax - [@namusyaka](https://github.com/namusyaka).
59
- * [#1499](https://github.com/ruby-grape/grape/pull/1499): Support fail_fast param validation option - [@dgasper](https://github.com/dgasper).
75
+ * [#1470](https://github.com/ruby-grape/grape/pull/1470): Dropped support for Ruby 2.0 - [@namusyaka](https://github.com/namusyaka).
76
+ * [#1490](https://github.com/ruby-grape/grape/pull/1490): Switched to Ruby-2.x+ syntax - [@namusyaka](https://github.com/namusyaka).
77
+ * [#1499](https://github.com/ruby-grape/grape/pull/1499): Support `fail_fast` param validation option - [@dgasper](https://github.com/dgasper).
60
78
 
61
79
  #### Fixes
62
80
 
63
- * [#1498](https://github.com/ruby-grape/grape/pull/1498): Skip validations in inactive given blocks - [@jlfaber](https://github.com/jlfaber).
64
- * [#1479](https://github.com/ruby-grape/grape/pull/1479): Support inserting middleware before/after anonymous classes in the middleware stack - [@rosa](https://github.com/rosa).
65
- * [#1488](https://github.com/ruby-grape/grape/pull/1488): Ensure calling before filters when receiving OPTIONS request - [@namusyaka](https://github.com/namusyaka), [@jlfaber](https://github.com/jlfaber).
66
- * [#1493](https://github.com/ruby-grape/grape/pull/1493): Coercion and lambda fails params validation - [@jonmchan](https://github.com/jonmchan).
81
+ * [#1498](https://github.com/ruby-grape/grape/pull/1498): Fix: skip validations in inactive given blocks - [@jlfaber](https://github.com/jlfaber).
82
+ * [#1479](https://github.com/ruby-grape/grape/pull/1479): Fix: support inserting middleware before/after anonymous classes in the middleware stack - [@rosa](https://github.com/rosa).
83
+ * [#1488](https://github.com/ruby-grape/grape/pull/1488): Fix: ensure calling before filters when receiving OPTIONS request - [@namusyaka](https://github.com/namusyaka), [@jlfaber](https://github.com/jlfaber).
84
+ * [#1493](https://github.com/ruby-grape/grape/pull/1493): Fix: coercion and lambda fails params validation - [@jonmchan](https://github.com/jonmchan).
67
85
 
68
86
  ### 0.17.0 (7/29/2016)
69
87
 
70
88
  #### Features
71
89
 
72
90
  * [#1393](https://github.com/ruby-grape/grape/pull/1393): Middleware can be inserted before or after default Grape middleware - [@ridiculous](https://github.com/ridiculous).
73
- * [#1390](https://github.com/ruby-grape/grape/pull/1390): Allow inserting middleware at arbitrary points in the middleware stack - [@rosa](https://github.com/rosa).
74
- * [#1366](https://github.com/ruby-grape/grape/pull/1366): Store `message_key` on `Grape::Exceptions::Validation` - [@mkou](https://github.com/mkou).
75
- * [#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).
76
- * [#1443](https://github.com/ruby-grape/grape/pull/1443): Extend `given` to receive a `Proc` - [@glaucocustodio](https://github.com/glaucocustodio).
77
- * [#1455](https://github.com/ruby-grape/grape/pull/1455): Add an automated PR linter - [@orta](https://github.com/orta).
91
+ * [#1390](https://github.com/ruby-grape/grape/pull/1390): Allowed inserting middleware at arbitrary points in the middleware stack - [@rosa](https://github.com/rosa).
92
+ * [#1366](https://github.com/ruby-grape/grape/pull/1366): Stored `message_key` on `Grape::Exceptions::Validation` - [@mkou](https://github.com/mkou).
93
+ * [#1398](https://github.com/ruby-grape/grape/pull/1398): Added `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).
94
+ * [#1443](https://github.com/ruby-grape/grape/pull/1443): Extended `given` to receive a `Proc` - [@glaucocustodio](https://github.com/glaucocustodio).
95
+ * [#1455](https://github.com/ruby-grape/grape/pull/1455): Added an automated PR linter - [@orta](https://github.com/orta).
78
96
 
79
97
  #### Fixes
80
98
 
data/Gemfile CHANGED
@@ -8,6 +8,7 @@ group :development, :test do
8
8
  gem 'bundler'
9
9
  gem 'rake'
10
10
  gem 'rubocop', '0.47.0'
11
+ gem 'hashie'
11
12
  end
12
13
 
13
14
  group :development do
@@ -1,12 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- grape (0.19.2)
4
+ grape (1.0.0)
5
5
  activesupport
6
6
  builder
7
- hashie (>= 2.1.0)
8
- multi_json (>= 1.3.2)
9
- multi_xml (>= 0.5.2)
10
7
  mustermann-grape (~> 1.0.0)
11
8
  rack (>= 1.3.0)
12
9
  rack-accept
@@ -15,14 +12,14 @@ PATH
15
12
  GEM
16
13
  remote: https://rubygems.org/
17
14
  specs:
18
- activesupport (5.0.1)
15
+ activesupport (5.1.2)
19
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
17
  i18n (~> 0.7)
21
18
  minitest (~> 5.1)
22
19
  tzinfo (~> 1.1)
23
- addressable (2.5.0)
20
+ addressable (2.5.1)
24
21
  public_suffix (~> 2.0, >= 2.0.2)
25
- appraisal (2.1.0)
22
+ appraisal (2.2.0)
26
23
  bundler
27
24
  rake
28
25
  thor (>= 0.14.0)
@@ -33,7 +30,7 @@ GEM
33
30
  thread_safe (~> 0.3, >= 0.3.1)
34
31
  benchmark-ips (2.7.2)
35
32
  builder (3.2.3)
36
- claide (1.0.1)
33
+ claide (1.0.2)
37
34
  claide-plugins (0.9.2)
38
35
  cork
39
36
  nap
@@ -42,17 +39,18 @@ GEM
42
39
  coercible (1.0.0)
43
40
  descendants_tracker (~> 0.0.1)
44
41
  colored (1.2)
45
- concurrent-ruby (1.0.4)
42
+ colored2 (3.1.2)
43
+ concurrent-ruby (1.0.5)
46
44
  cookiejar (0.3.3)
47
- cork (0.2.0)
48
- colored (~> 1.2)
49
- coveralls (0.8.19)
45
+ cork (0.3.0)
46
+ colored2 (~> 3.1)
47
+ coveralls (0.8.21)
50
48
  json (>= 1.8, < 3)
51
- simplecov (~> 0.12.0)
49
+ simplecov (~> 0.14.1)
52
50
  term-ansicolor (~> 1.3)
53
- thor (~> 0.19.1)
51
+ thor (~> 0.19.4)
54
52
  tins (~> 1.6)
55
- danger (4.0.3)
53
+ danger (4.0.5)
56
54
  claide (~> 1.0)
57
55
  claide-plugins (>= 0.9.2)
58
56
  colored (~> 1.2)
@@ -69,20 +67,20 @@ GEM
69
67
  danger (> 2.0)
70
68
  descendants_tracker (0.0.4)
71
69
  thread_safe (~> 0.3, >= 0.3.1)
72
- diff-lcs (1.2.5)
70
+ diff-lcs (1.3)
73
71
  docile (1.1.5)
74
72
  equalizer (0.0.11)
75
- faraday (0.10.0)
73
+ faraday (0.12.1)
76
74
  multipart-post (>= 1.2, < 3)
77
75
  faraday-http-cache (1.3.1)
78
76
  faraday (~> 0.8)
79
- ffi (1.9.14)
77
+ ffi (1.9.18)
80
78
  formatador (0.2.5)
81
79
  git (1.3.0)
82
- grape-entity (0.6.0)
83
- activesupport
80
+ grape-entity (0.6.1)
81
+ activesupport (>= 5.0.0)
84
82
  multi_json (>= 1.3.2)
85
- guard (2.14.0)
83
+ guard (2.14.1)
86
84
  formatador (>= 0.2.4)
87
85
  listen (>= 2.7, < 4.0)
88
86
  lumberjack (~> 1.0)
@@ -96,27 +94,26 @@ GEM
96
94
  guard (~> 2.1)
97
95
  guard-compat (~> 1.1)
98
96
  rspec (>= 2.99.0, < 4.0)
99
- guard-rubocop (1.2.0)
97
+ guard-rubocop (1.3.0)
100
98
  guard (~> 2.0)
101
99
  rubocop (~> 0.20)
102
100
  hashie (3.5.5)
103
- i18n (0.7.0)
101
+ i18n (0.8.4)
104
102
  ice_nine (0.11.2)
105
- json (2.0.3)
106
- kramdown (1.13.1)
103
+ json (2.1.0)
104
+ kramdown (1.14.0)
107
105
  listen (3.1.5)
108
106
  rb-fsevent (~> 0.9, >= 0.9.4)
109
107
  rb-inotify (~> 0.9, >= 0.9.7)
110
108
  ruby_dep (~> 1.2)
111
- lumberjack (1.0.10)
112
- maruku (0.7.2)
109
+ lumberjack (1.0.12)
110
+ maruku (0.7.3)
113
111
  method_source (0.8.2)
114
112
  mime-types (3.1)
115
113
  mime-types-data (~> 3.2015)
116
114
  mime-types-data (3.2016.0521)
117
- minitest (5.10.1)
115
+ minitest (5.10.2)
118
116
  multi_json (1.12.1)
119
- multi_xml (0.6.0)
120
117
  multipart-post (2.0.0)
121
118
  mustermann (1.0.0)
122
119
  mustermann-grape (1.0.0)
@@ -126,43 +123,44 @@ GEM
126
123
  notiffany (0.1.1)
127
124
  nenv (~> 0.1)
128
125
  shellany (~> 0.0)
129
- octokit (4.6.2)
126
+ octokit (4.7.0)
130
127
  sawyer (~> 0.8.0, >= 0.5.3)
131
128
  open4 (1.3.4)
132
- parser (2.3.3.1)
129
+ parser (2.4.0.0)
133
130
  ast (~> 2.2)
134
131
  powerpack (0.1.1)
135
132
  pry (0.10.4)
136
133
  coderay (~> 1.1.0)
137
134
  method_source (~> 0.8.1)
138
135
  slop (~> 3.4)
139
- public_suffix (2.0.4)
140
- rack (2.0.1)
136
+ public_suffix (2.0.5)
137
+ rack (2.0.3)
141
138
  rack-accept (0.4.5)
142
139
  rack (>= 0.4)
143
140
  rack-jsonp (1.3.1)
144
141
  rack
145
142
  rack-test (0.6.3)
146
143
  rack (>= 1.0)
147
- rainbow (2.2.1)
144
+ rainbow (2.2.2)
145
+ rake
148
146
  rake (12.0.0)
149
- rb-fsevent (0.9.8)
150
- rb-inotify (0.9.7)
151
- ffi (>= 0.5.0)
147
+ rb-fsevent (0.10.2)
148
+ rb-inotify (0.9.10)
149
+ ffi (>= 0.5.0, < 2)
152
150
  redcarpet (3.4.0)
153
- rspec (3.5.0)
154
- rspec-core (~> 3.5.0)
155
- rspec-expectations (~> 3.5.0)
156
- rspec-mocks (~> 3.5.0)
157
- rspec-core (3.5.4)
158
- rspec-support (~> 3.5.0)
159
- rspec-expectations (3.5.0)
151
+ rspec (3.6.0)
152
+ rspec-core (~> 3.6.0)
153
+ rspec-expectations (~> 3.6.0)
154
+ rspec-mocks (~> 3.6.0)
155
+ rspec-core (3.6.0)
156
+ rspec-support (~> 3.6.0)
157
+ rspec-expectations (3.6.0)
160
158
  diff-lcs (>= 1.2.0, < 2.0)
161
- rspec-support (~> 3.5.0)
162
- rspec-mocks (3.5.0)
159
+ rspec-support (~> 3.6.0)
160
+ rspec-mocks (3.6.0)
163
161
  diff-lcs (>= 1.2.0, < 2.0)
164
- rspec-support (~> 3.5.0)
165
- rspec-support (3.5.0)
162
+ rspec-support (~> 3.6.0)
163
+ rspec-support (3.6.0)
166
164
  rubocop (0.47.0)
167
165
  parser (>= 2.3.3.1, < 3.0)
168
166
  powerpack (~> 0.1)
@@ -178,28 +176,28 @@ GEM
178
176
  addressable (>= 2.3.5, < 2.6)
179
177
  faraday (~> 0.8, < 1.0)
180
178
  shellany (0.0.1)
181
- simplecov (0.12.0)
179
+ simplecov (0.14.1)
182
180
  docile (~> 1.1.0)
183
181
  json (>= 1.8, < 3)
184
182
  simplecov-html (~> 0.10.0)
185
- simplecov-html (0.10.0)
183
+ simplecov-html (0.10.1)
186
184
  slop (3.6.0)
187
- term-ansicolor (1.4.0)
185
+ term-ansicolor (1.6.0)
188
186
  tins (~> 1.0)
189
- terminal-table (1.7.3)
190
- unicode-display_width (~> 1.1.1)
187
+ terminal-table (1.8.0)
188
+ unicode-display_width (~> 1.1, >= 1.1.1)
191
189
  thor (0.19.4)
192
- thread_safe (0.3.5)
193
- tins (1.13.0)
194
- tzinfo (1.2.2)
190
+ thread_safe (0.3.6)
191
+ tins (1.15.0)
192
+ tzinfo (1.2.3)
195
193
  thread_safe (~> 0.1)
196
- unicode-display_width (1.1.3)
194
+ unicode-display_width (1.3.0)
197
195
  virtus (1.0.5)
198
196
  axiom-types (~> 0.1)
199
197
  coercible (~> 1.0)
200
198
  descendants_tracker (~> 0.0, >= 0.0.3)
201
199
  equalizer (~> 0.0, >= 0.0.9)
202
- yard (0.9.5)
200
+ yard (0.9.9)
203
201
 
204
202
  PLATFORMS
205
203
  ruby
@@ -215,6 +213,7 @@ DEPENDENCIES
215
213
  guard
216
214
  guard-rspec
217
215
  guard-rubocop
216
+ hashie
218
217
  maruku
219
218
  mime-types
220
219
  rack-jsonp
@@ -227,4 +226,4 @@ DEPENDENCIES
227
226
  yard
228
227
 
229
228
  BUNDLED WITH
230
- 1.13.7
229
+ 1.14.6
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2015 Michael Bleigh and Intridea, Inc.
1
+ Copyright (c) 2010-2017 Michael Bleigh and Intridea, Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -29,6 +29,7 @@
29
29
  - [Param](#param)
30
30
  - [Describing Methods](#describing-methods)
31
31
  - [Parameters](#parameters)
32
+ - [Params Class](#params-class)
32
33
  - [Declared](#declared)
33
34
  - [Include Missing](#include-missing)
34
35
  - [Parameter Validation and Coercion](#parameter-validation-and-coercion)
@@ -68,6 +69,7 @@
68
69
  - [CORS](#cors)
69
70
  - [Content-type](#content-type)
70
71
  - [API Data Formats](#api-data-formats)
72
+ - [JSON and XML Processors](#json-and-xml-processors)
71
73
  - [RESTful Model Representations](#restful-model-representations)
72
74
  - [Grape Entities](#grape-entities)
73
75
  - [Hypermedia and Roar](#hypermedia-and-roar)
@@ -107,7 +109,7 @@ content negotiation, versioning and much more.
107
109
 
108
110
  ## Stable Release
109
111
 
110
- You're reading the documentation for the stable release of Grape.
112
+ You're reading the documentation for the stable release of Grape, 1.0.0.
111
113
  Please read [UPGRADING](UPGRADING.md) when upgrading from a previous version.
112
114
 
113
115
  ## Project Resources
@@ -423,7 +425,7 @@ desc 'Returns your public timeline.' do
423
425
  failure [[401, 'Unauthorized', 'Entities::Error']]
424
426
  named 'My named route'
425
427
  headers XAuthToken: {
426
- description: 'Valdates your identity',
428
+ description: 'Validates your identity',
427
429
  required: true
428
430
  },
429
431
  XOptionalHeader: {
@@ -494,7 +496,36 @@ In the case of conflict between either of:
494
496
  * `GET`, `POST` and `PUT` parameters
495
497
  * the contents of the request body on `POST` and `PUT`
496
498
 
497
- route string parameters will have precedence.
499
+ Route string parameters will have precedence.
500
+
501
+ ### Params Class
502
+
503
+ By default parameters are available as `ActiveSupport::HashWithIndifferentAccess`. This can be changed to, for example, Ruby `Hash` or `Hashie::Mash` for the entire API.
504
+
505
+ ```ruby
506
+ class API < Grape::API
507
+ include Grape::Extensions::Hashie::Mash::ParamBuilder
508
+
509
+ params do
510
+ optional :color, type: String
511
+ end
512
+ get do
513
+ params.color # instead of params[:color]
514
+ end
515
+ ```
516
+
517
+ The class can also be overridden on individual parameter blocks using `build_with` as follows.
518
+
519
+ ```ruby
520
+ params do
521
+ build_with Grape::Extensions::Hash::ParamBuilder
522
+ optional :color, type: String
523
+ end
524
+ ```
525
+
526
+ In the example above, `params["color"]` will return `nil` since `params` is a plain `Hash`.
527
+
528
+ Available parameter builders are `Grape::Extensions::Hash::ParamBuilder`, `Grape::Extensions::ActiveSupport::HashWithIndifferentAccess::ParamBuilder` and `Grape::Extensions::Hashie::Mash::ParamBuilder`.
498
529
 
499
530
  ### Declared
500
531
 
@@ -508,7 +539,7 @@ post 'users/signup' do
508
539
  end
509
540
  ````
510
541
 
511
- If we do not specify any params, `declared` will return an empty `Hashie::Mash` instance.
542
+ If you do not specify any parameters, `declared` will return an empty hash.
512
543
 
513
544
  **Request**
514
545
 
@@ -525,7 +556,7 @@ curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d
525
556
 
526
557
  ````
527
558
 
528
- Once we add parameters requirements, grape will start returning only the declared params.
559
+ Once we add parameters requirements, grape will start returning only the declared parameters.
529
560
 
530
561
  ````ruby
531
562
  format :json
@@ -561,17 +592,11 @@ curl -X POST -H "Content-Type: application/json" localhost:9292/users/signup -d
561
592
  }
562
593
  ````
563
594
 
564
- The returned hash is a `Hashie::Mash` instance, allowing you to access parameters via dot notation:
595
+ The returned hash is an `ActiveSupport::HashWithIndifferentAccess`.
565
596
 
566
- ```ruby
567
- declared(params).user == declared(params)['user']
568
- ```
569
-
570
-
571
- The `#declared` method is not available to `before` filters, as those are evaluated prior
572
- to parameter coercion.
597
+ The `#declared` method is not available to `before` filters, as those are evaluated prior to parameter coercion.
573
598
 
574
- ### Include parent namespaces
599
+ ### Include Parent Namespaces
575
600
 
576
601
  By default `declared(params)` includes parameters that were defined in all parent namespaces. If you want to return only parameters from your current namespace, you can set `include_parent_namespaces` option to `false`.
577
602
 
@@ -782,6 +807,10 @@ end
782
807
  Note that default values will be passed through to any validation options specified.
783
808
  The following example will always fail if `:color` is not explicitly provided.
784
809
 
810
+ Default values are eagerly evaluated. Above `:non_random_number` will evaluate to the same
811
+ number for each call to the endpoint of this `params` block. To have the default evaluate
812
+ lazily with each request use a lambda, like `:random_number` above.
813
+
785
814
  ```ruby
786
815
  params do
787
816
  optional :color, type: String, default: 'blue', values: ['red', 'green']
@@ -896,18 +925,16 @@ end
896
925
 
897
926
  ### Multipart File Parameters
898
927
 
899
- Grape makes use of `Rack::Request`'s built-in support for multipart
900
- file parameters. Such parameters can be declared with `type: File`:
928
+ Grape makes use of `Rack::Request`'s built-in support for multipart file parameters. Such parameters can be declared with `type: File`:
901
929
 
902
930
  ```ruby
903
931
  params do
904
932
  requires :avatar, type: File
905
933
  end
906
934
  post '/' do
907
- # Parameter will be wrapped using Hashie:
908
- params.avatar.filename # => 'avatar.png'
909
- params.avatar.type # => 'image/png'
910
- params.avatar.tempfile # => #<File>
935
+ params[:avatar][:filename] # => 'avatar.png'
936
+ params[:avatar][:avatar] # => 'image/png'
937
+ params[:avatar][:tempfile] # => #<File>
911
938
  end
912
939
  ```
913
940
 
@@ -1091,9 +1118,6 @@ end
1091
1118
 
1092
1119
  Parameters can be restricted to a specific set of values with the `:values` option.
1093
1120
 
1094
- Default values are eagerly evaluated. Above `:non_random_number` will evaluate to the same
1095
- number for each call to the endpoint of this `params` block. To have the default evaluate
1096
- lazily with each request use a lambda, like `:random_number` above.
1097
1121
 
1098
1122
  ```ruby
1099
1123
  params do
@@ -1112,7 +1136,7 @@ params do
1112
1136
  end
1113
1137
  ```
1114
1138
 
1115
- Note that *both* range endpoints have to be a `#kind_of?` your `:type` option (if you don't supplied the `:type` option, it will be guessed to be equal to the class of the range's first endpoint). So the following is invalid:
1139
+ Note that *both* range endpoints have to be a `#kind_of?` your `:type` option (if you don't supply the `:type` option, it will be guessed to be equal to the class of the range's first endpoint). So the following is invalid:
1116
1140
 
1117
1141
  ```ruby
1118
1142
  params do
@@ -1122,6 +1146,9 @@ end
1122
1146
  ```
1123
1147
 
1124
1148
  The `:values` option can also be supplied with a `Proc`, evaluated lazily with each request.
1149
+ If the Proc has arity zero (i.e. it takes no arguments) it is expected to return either a list
1150
+ or a range which will then be used to validate the parameter.
1151
+
1125
1152
  For example, given a status model you may want to restrict by hashtags that you have
1126
1153
  previously defined in the `HashTag` model.
1127
1154
 
@@ -1131,40 +1158,34 @@ params do
1131
1158
  end
1132
1159
  ```
1133
1160
 
1134
- The values validator can also validate that the value is explicitly not within a specific
1135
- set of values by passing ```except```. ```except``` accepts the same types of parameters as
1136
- values (Procs, ranges, etc.).
1161
+ Alternatively, a Proc with arity one (i.e. taking one argument) can be used to explicitly validate
1162
+ each parameter value. In that case, the Proc is expected to return a truthy value if the parameter
1163
+ value is valid.
1137
1164
 
1138
1165
  ```ruby
1139
1166
  params do
1140
- requires :browsers, values: { except: [ 'ie6', 'ie7', 'ie8' ] }
1167
+ requires :number, type: Integer, values: ->(v) { v.even? && v < 25 }
1141
1168
  end
1142
1169
  ```
1143
1170
 
1144
- Values and except can be combined to define a range of accepted values while not allowing
1145
- certain values within the set. Custom error messages can be defined for both when the parameter
1146
- passed falls within the ```except``` list or when it falls entirely outside the ```value``` list.
1171
+ While Procs are convenient for single cases, consider using [Custom Validators](#custom-validators) in cases where a validation is used more than once.
1147
1172
 
1148
- ```ruby
1149
- params do
1150
- requires :number, type: Integer, values: { value: 1..20, except: [4, 13], except_message: 'includes unsafe numbers', message: 'is outside the range of numbers allowed' }
1151
- end
1152
- ```
1173
+ #### `except_values`
1174
+
1175
+ Parameters can be restricted from having a specific set of values with the `:except_values` option.
1153
1176
 
1154
- Finally, for even greater control, an explicit validation Proc may be supplied using ```proc```.
1155
- It will be called with a single argument (the input value), and should return
1156
- a truthy value if the value passes validation. If the input is an array, the Proc will be called
1157
- multiple times, once for each element in the array.
1177
+ The `except_values` validator behaves similarly to the `values` validator in that it accepts either
1178
+ an Array, a Range, or a Proc. Unlike the `values` validator, however, `except_values` only accepts
1179
+ Procs with arity zero.
1158
1180
 
1159
1181
  ```ruby
1160
1182
  params do
1161
- requires :number, type: Integer, values: { proc: ->(v) { v.even? && v < 25 }, message: 'is odd or greater than 25' }
1183
+ requires :browser, except_values: [ 'ie6', 'ie7', 'ie8' ]
1184
+ requires :port, except_values: { value: 0..1024, message: 'is not allowed' }
1185
+ requires :hashtag, except_values: -> { Hashtag.FORBIDDEN_LIST }
1162
1186
  end
1163
1187
  ```
1164
1188
 
1165
- While ```proc``` is convenient for single cases, consider using [Custom Validators](#custom-validators) in cases where a validation is used more than once.
1166
-
1167
-
1168
1189
  #### `regexp`
1169
1190
 
1170
1191
  Parameters can be restricted to match a specific regular expression with the `:regexp` option. If the value
@@ -1380,7 +1401,7 @@ class Admin < Grape::Validations::Base
1380
1401
  # @attrs is a list containing the attribute we are currently validating
1381
1402
  # in our sample case this method once will get called with
1382
1403
  # @attrs being [:admin_field] and once with @attrs being [:admin_false_field]
1383
- return unless request.params.key? @attrs.first
1404
+ return unless request.params.key?(@attrs.first)
1384
1405
  # check if admin flag is set to true
1385
1406
  return unless @option
1386
1407
  # check if user is admin or not
@@ -1400,6 +1421,8 @@ params do
1400
1421
  end
1401
1422
  ```
1402
1423
 
1424
+ Every validation will have it's own instance of the validator, which means that the validator can have a state.
1425
+
1403
1426
  ### Validation Errors
1404
1427
 
1405
1428
  Validation and coercion errors are collected and an exception of type `Grape::Exceptions::ValidationErrors` is raised. If the exception goes uncaught it will respond with a status of 400 and an error message. The validation errors are grouped by parameter name and can be accessed via `Grape::Exceptions::ValidationErrors#errors`.
@@ -1622,7 +1645,7 @@ end
1622
1645
  ## Helpers
1623
1646
 
1624
1647
  You can define helper methods that your endpoints can use with the `helpers`
1625
- macro by either giving a block or a module.
1648
+ macro by either giving a block or an array of modules.
1626
1649
 
1627
1650
  ```ruby
1628
1651
  module StatusHelpers
@@ -1631,6 +1654,12 @@ module StatusHelpers
1631
1654
  end
1632
1655
  end
1633
1656
 
1657
+ module HttpCodesHelpers
1658
+ def unauthorized
1659
+ 401
1660
+ end
1661
+ end
1662
+
1634
1663
  class API < Grape::API
1635
1664
  # define helpers with a block
1636
1665
  helpers do
@@ -1639,8 +1668,12 @@ class API < Grape::API
1639
1668
  end
1640
1669
  end
1641
1670
 
1642
- # or mix in a module
1643
- helpers StatusHelpers
1671
+ # or mix in an array of modules
1672
+ helpers StatusHelpers, HttpCodesHelpers
1673
+
1674
+ before do
1675
+ error!('Access Denied', unauthorized) unless current_user
1676
+ end
1644
1677
 
1645
1678
  get 'info' do
1646
1679
  # helpers available in your endpoint and filters
@@ -2533,6 +2566,10 @@ curl -X PUT -d 'data' 'http://localhost:9292/value' -H Content-Type:text/custom
2533
2566
 
2534
2567
  You can disable parsing for a content-type with `nil`. For example, `parser :json, nil` will disable JSON parsing altogether. The request data is then available as-is in `env['api.request.body']`.
2535
2568
 
2569
+ ## JSON and XML Processors
2570
+
2571
+ Grape uses `JSON` and `ActiveSupport::XmlMini` for JSON and XML parsing by default. It also detects and supports [multi_json](https://github.com/intridea/multi_json) and [multi_xml](https://github.com/sferik/multi_xml). Adding those gems to your Gemfile and requiring them will enable them and allow you to swap the JSON and XML back-ends.
2572
+
2536
2573
  ## RESTful Model Representations
2537
2574
 
2538
2575
  Grape supports a range of ways to present your data with some help from a generic `present` method,
@@ -3346,6 +3383,14 @@ The execution of the main content block of the endpoint.
3346
3383
  * *filters* - The filters being executed
3347
3384
  * *type* - The type of filters (before, before_validation, after_validation, after)
3348
3385
 
3386
+ #### endpoint_run_validators.grape
3387
+
3388
+ The execution of validators.
3389
+
3390
+ * *endpoint* - The endpoint instance
3391
+ * *validators* - The validators being executed
3392
+ * *request* - The request being validated
3393
+
3349
3394
  See the [ActiveSupport::Notifications documentation](http://api.rubyonrails.org/classes/ActiveSupport/Notifications.html) for information on how to subscribe to these events.
3350
3395
 
3351
3396
  ### Monitoring Products
@@ -3370,4 +3415,4 @@ MIT License. See LICENSE for details.
3370
3415
 
3371
3416
  ## Copyright
3372
3417
 
3373
- Copyright (c) 2010-2015 Michael Bleigh, and Intridea, Inc.
3418
+ Copyright (c) 2010-2017 Michael Bleigh, and Intridea, Inc.