grape 0.3.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of grape might be problematic. Click here for more details.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/.rubocop.yml +70 -0
- data/.travis.yml +7 -6
- data/CHANGELOG.md +134 -4
- data/CONTRIBUTING.md +118 -0
- data/Gemfile +5 -2
- data/README.md +551 -116
- data/RELEASING.md +105 -0
- data/Rakefile +29 -8
- data/UPGRADING.md +124 -0
- data/grape.gemspec +3 -3
- data/lib/grape/api.rb +207 -88
- data/lib/grape/cookies.rb +4 -8
- data/lib/grape/endpoint.rb +198 -144
- data/lib/grape/error_formatter/base.rb +5 -7
- data/lib/grape/error_formatter/json.rb +3 -5
- data/lib/grape/error_formatter/txt.rb +1 -3
- data/lib/grape/error_formatter/xml.rb +4 -6
- data/lib/grape/exceptions/base.rb +9 -9
- data/lib/grape/exceptions/incompatible_option_values.rb +10 -0
- data/lib/grape/exceptions/invalid_formatter.rb +1 -4
- data/lib/grape/exceptions/invalid_versioner_option.rb +1 -5
- data/lib/grape/exceptions/invalid_with_option_for_represent.rb +1 -6
- data/lib/grape/exceptions/missing_mime_type.rb +1 -5
- data/lib/grape/exceptions/missing_option.rb +1 -4
- data/lib/grape/exceptions/missing_vendor_option.rb +1 -4
- data/lib/grape/exceptions/unknown_options.rb +1 -5
- data/lib/grape/exceptions/unknown_validator.rb +1 -3
- data/lib/grape/exceptions/validation.rb +13 -3
- data/lib/grape/exceptions/validation_errors.rb +43 -0
- data/lib/grape/formatter/base.rb +5 -7
- data/lib/grape/formatter/json.rb +0 -3
- data/lib/grape/formatter/serializable_hash.rb +15 -15
- data/lib/grape/formatter/txt.rb +0 -2
- data/lib/grape/formatter/xml.rb +0 -2
- data/lib/grape/http/request.rb +26 -0
- data/lib/grape/locale/en.yml +8 -5
- data/lib/grape/middleware/auth/base.rb +30 -0
- data/lib/grape/middleware/auth/basic.rb +3 -20
- data/lib/grape/middleware/auth/digest.rb +2 -19
- data/lib/grape/middleware/auth/oauth2.rb +31 -24
- data/lib/grape/middleware/base.rb +7 -7
- data/lib/grape/middleware/error.rb +36 -22
- data/lib/grape/middleware/filter.rb +3 -3
- data/lib/grape/middleware/formatter.rb +99 -61
- data/lib/grape/middleware/globals.rb +13 -0
- data/lib/grape/middleware/versioner/accept_version_header.rb +67 -0
- data/lib/grape/middleware/versioner/header.rb +22 -16
- data/lib/grape/middleware/versioner/param.rb +9 -11
- data/lib/grape/middleware/versioner/path.rb +10 -13
- data/lib/grape/middleware/versioner.rb +3 -1
- data/lib/grape/namespace.rb +23 -0
- data/lib/grape/parser/base.rb +3 -5
- data/lib/grape/parser/json.rb +0 -2
- data/lib/grape/parser/xml.rb +0 -2
- data/lib/grape/path.rb +70 -0
- data/lib/grape/route.rb +10 -6
- data/lib/grape/util/content_types.rb +2 -1
- data/lib/grape/util/deep_merge.rb +5 -5
- data/lib/grape/util/hash_stack.rb +13 -2
- data/lib/grape/validations/coerce.rb +11 -10
- data/lib/grape/validations/default.rb +25 -0
- data/lib/grape/validations/presence.rb +7 -3
- data/lib/grape/validations/regexp.rb +2 -5
- data/lib/grape/validations/values.rb +17 -0
- data/lib/grape/validations.rb +161 -54
- data/lib/grape/version.rb +1 -1
- data/lib/grape.rb +19 -4
- data/spec/grape/api_spec.rb +897 -268
- data/spec/grape/endpoint_spec.rb +283 -66
- data/spec/grape/entity_spec.rb +132 -29
- data/spec/grape/exceptions/missing_mime_type_spec.rb +3 -9
- data/spec/grape/exceptions/validation_errors_spec.rb +19 -0
- data/spec/grape/middleware/auth/basic_spec.rb +8 -8
- data/spec/grape/middleware/auth/digest_spec.rb +5 -5
- data/spec/grape/middleware/auth/oauth2_spec.rb +81 -36
- data/spec/grape/middleware/base_spec.rb +8 -13
- data/spec/grape/middleware/error_spec.rb +13 -17
- data/spec/grape/middleware/exception_spec.rb +47 -27
- data/spec/grape/middleware/formatter_spec.rb +103 -41
- data/spec/grape/middleware/versioner/accept_version_header_spec.rb +121 -0
- data/spec/grape/middleware/versioner/header_spec.rb +76 -51
- data/spec/grape/middleware/versioner/param_spec.rb +18 -18
- data/spec/grape/middleware/versioner/path_spec.rb +6 -6
- data/spec/grape/middleware/versioner_spec.rb +5 -2
- data/spec/grape/path_spec.rb +229 -0
- data/spec/grape/util/hash_stack_spec.rb +31 -32
- data/spec/grape/validations/coerce_spec.rb +116 -51
- data/spec/grape/validations/default_spec.rb +123 -0
- data/spec/grape/validations/presence_spec.rb +42 -44
- data/spec/grape/validations/regexp_spec.rb +9 -9
- data/spec/grape/validations/values_spec.rb +138 -0
- data/spec/grape/validations/zh-CN.yml +4 -3
- data/spec/grape/validations_spec.rb +681 -48
- data/spec/shared/versioning_examples.rb +22 -6
- data/spec/spec_helper.rb +3 -2
- data/spec/support/basic_auth_encode_helpers.rb +0 -1
- data/spec/support/content_type_helpers.rb +11 -0
- data/spec/support/versioned_helpers.rb +13 -5
- metadata +34 -84
data/RELEASING.md
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
Releasing Grape
|
2
|
+
===============
|
3
|
+
|
4
|
+
There're no particular rules about when to release Grape. Release bug fixes frequenty, features not so frequently and breaking API changes rarely.
|
5
|
+
|
6
|
+
### Release
|
7
|
+
|
8
|
+
Run tests, check that all tests succeed locally.
|
9
|
+
|
10
|
+
```
|
11
|
+
bundle install
|
12
|
+
rake
|
13
|
+
```
|
14
|
+
|
15
|
+
Check that the last build succeeded in [Travis CI](https://travis-ci.org/intridea/grape) for all supported platforms.
|
16
|
+
|
17
|
+
Those with r/w permissions to the [master Intridea repository](https://github.com/intridea/grape) generally have large Grape-based projects. Point one to Grape HEAD and run all your API tests to catch any obvious regressions.
|
18
|
+
|
19
|
+
```
|
20
|
+
gem grape, github: 'intridea/grape'
|
21
|
+
```
|
22
|
+
|
23
|
+
Increment the version, modify [lib/grape/version.rb](lib/grape/version.rb).
|
24
|
+
|
25
|
+
* Increment the third number if the release has bug fixes and/or very minor features, only (eg. change `0.5.1` to `0.5.2`).
|
26
|
+
* Increment the second number if the release contains major features or breaking API changes (eg. change `0.5.1` to `0.6.0`).
|
27
|
+
|
28
|
+
Modify the "Stable Release" section in [README.md](README.md). Change the text to reflect that this is going to be the documentation for a stable release. Remove references to the previous release of Grape. Keep the file open, you'll have to undo this change after the release.
|
29
|
+
|
30
|
+
```
|
31
|
+
## Stable Release
|
32
|
+
|
33
|
+
You're reading the documentation for the stable release of Grape, 0.6.0.
|
34
|
+
```
|
35
|
+
|
36
|
+
Change "Next Release" in [CHANGELOG.md](CHANGELOG.md) to the new version.
|
37
|
+
|
38
|
+
```
|
39
|
+
0.6.0 (9/16/2013)
|
40
|
+
=================
|
41
|
+
```
|
42
|
+
|
43
|
+
Remove the line with "Your contribution here.", since there will be no more contributions to this release.
|
44
|
+
|
45
|
+
Commit your changes.
|
46
|
+
|
47
|
+
```
|
48
|
+
git add README.md CHANGELOG.md lib/grape/version.rb
|
49
|
+
git commit -m "Preparing for release, 0.6.0."
|
50
|
+
git push origin master
|
51
|
+
```
|
52
|
+
|
53
|
+
Release.
|
54
|
+
|
55
|
+
```
|
56
|
+
$ rake release
|
57
|
+
|
58
|
+
grape 0.6.0 built to pkg/grape-0.6.0.gem.
|
59
|
+
Tagged v0.6.0.
|
60
|
+
Pushed git commits and tags.
|
61
|
+
Pushed grape 0.6.0 to rubygems.org.
|
62
|
+
```
|
63
|
+
|
64
|
+
### Prepare for the Next Version
|
65
|
+
|
66
|
+
Modify the "Stable Release" section in [README.md](README.md). Change the text to reflect that this is going to be the next release.
|
67
|
+
|
68
|
+
```
|
69
|
+
## Stable Release
|
70
|
+
|
71
|
+
You're reading the documentation for the next release of Grape, which should be 0.6.1.
|
72
|
+
The current stable release is [0.6.0](https://github.com/intridea/grape/blob/v0.6.0/README.md).
|
73
|
+
```
|
74
|
+
|
75
|
+
Add the next release to [CHANGELOG.md](CHANGELOG.md).
|
76
|
+
|
77
|
+
```
|
78
|
+
Next Release
|
79
|
+
============
|
80
|
+
|
81
|
+
* Your contribution here.
|
82
|
+
```
|
83
|
+
|
84
|
+
Comit your changes.
|
85
|
+
|
86
|
+
```
|
87
|
+
git add CHANGELOG.md README.md
|
88
|
+
git commit -m "Preparing for next release."
|
89
|
+
git push origin master
|
90
|
+
```
|
91
|
+
|
92
|
+
### Make an Announcement
|
93
|
+
|
94
|
+
Make an announcement on the [ruby-grape@googlegroups.com](mailto:ruby-grape@googlegroups.com) mailing list. The general format is as follows.
|
95
|
+
|
96
|
+
```
|
97
|
+
Grape 0.6.0 has been released.
|
98
|
+
|
99
|
+
There were 8 contributors to this release, not counting documentation.
|
100
|
+
|
101
|
+
Please note the breaking API change in ...
|
102
|
+
|
103
|
+
[copy/paste CHANGELOG here]
|
104
|
+
|
105
|
+
```
|
data/Rakefile
CHANGED
@@ -15,29 +15,50 @@ RSpec::Core::RakeTask.new(:rcov) do |spec|
|
|
15
15
|
end
|
16
16
|
|
17
17
|
task :spec
|
18
|
-
|
18
|
+
|
19
|
+
require 'rainbow/ext/string' unless String.respond_to?(:color)
|
20
|
+
require 'rubocop/rake_task'
|
21
|
+
Rubocop::RakeTask.new(:rubocop)
|
22
|
+
|
23
|
+
task default: [:rubocop, :spec]
|
19
24
|
|
20
25
|
begin
|
21
26
|
require 'yard'
|
22
|
-
DOC_FILES = ['lib/**/*.rb', 'README.
|
23
|
-
|
27
|
+
DOC_FILES = ['lib/**/*.rb', 'README.md']
|
28
|
+
|
24
29
|
YARD::Rake::YardocTask.new(:doc) do |t|
|
25
30
|
t.files = DOC_FILES
|
26
31
|
end
|
27
|
-
|
32
|
+
|
28
33
|
namespace :doc do
|
29
34
|
YARD::Rake::YardocTask.new(:pages) do |t|
|
30
35
|
t.files = DOC_FILES
|
31
|
-
t.options = ['-o', '../grape.doc']
|
36
|
+
t.options = ['-o', '../grape.doc/docs']
|
32
37
|
end
|
33
|
-
|
38
|
+
|
34
39
|
namespace :pages do
|
40
|
+
|
41
|
+
desc "Check out gh-pages."
|
42
|
+
task :checkout do
|
43
|
+
dir = File.dirname(__FILE__) + '/../grape.doc'
|
44
|
+
unless Dir.exist?(dir)
|
45
|
+
Dir.mkdir(dir)
|
46
|
+
Dir.chdir(dir) do
|
47
|
+
system("git init")
|
48
|
+
system("git remote add origin git@github.com:intridea/grape.git")
|
49
|
+
system("git pull")
|
50
|
+
system("git checkout gh-pages")
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
35
55
|
desc 'Generate and publish YARD docs to GitHub pages.'
|
36
|
-
task :publish => ['doc:pages'] do
|
56
|
+
task :publish => ['doc:pages:checkout', 'doc:pages'] do
|
37
57
|
Dir.chdir(File.dirname(__FILE__) + '/../grape.doc') do
|
58
|
+
system("git checkout gh-pages")
|
38
59
|
system("git add .")
|
39
60
|
system("git add -u")
|
40
|
-
system("git commit -m 'Generating docs for version #{
|
61
|
+
system("git commit -m 'Generating docs for version #{Grape::VERSION}.'")
|
41
62
|
system("git push origin gh-pages")
|
42
63
|
end
|
43
64
|
end
|
data/UPGRADING.md
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
Upgrading Grape
|
2
|
+
===============
|
3
|
+
|
4
|
+
### Upgrading to 0.7.0
|
5
|
+
|
6
|
+
#### Changes in Exception Handling
|
7
|
+
|
8
|
+
Assume you have the following exception classes defined.
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
class ParentError < StandardError; end
|
12
|
+
class ChildError < ParentError; end
|
13
|
+
```
|
14
|
+
|
15
|
+
In Grape <= 0.6.1, the `rescue_from` keyword only handled the exact exception being raised. The following code would rescue `ParentError`, but not `ChildError`.
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
rescue_from ParentError do |e|
|
19
|
+
# only rescue ParentError
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
This made it impossible to rescue an exception hieararchy, which is a more sensible default. In Grape 0.7.0 or newer, both `ParentError` and `ChildError` are rescued.
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
rescue_from ParentError do |e|
|
27
|
+
# rescue both ParentError and ChildError
|
28
|
+
end
|
29
|
+
```
|
30
|
+
|
31
|
+
To only rescue the base exception class, set `rescue_subclasses: false`.
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
rescue_from ParentError, rescue_subclasses: false do |e|
|
35
|
+
# only rescue ParentError
|
36
|
+
end
|
37
|
+
```
|
38
|
+
|
39
|
+
See [#544](https://github.com/intridea/grape/pull/544) for more information.
|
40
|
+
|
41
|
+
|
42
|
+
#### Changes in the Default HTTP Status Code
|
43
|
+
|
44
|
+
In Grape <= 0.6.1, the default status code returned from `error!` was 403.
|
45
|
+
|
46
|
+
```ruby
|
47
|
+
error! "You may not reticulate this spline!" # yields HTTP error 403
|
48
|
+
```
|
49
|
+
|
50
|
+
This was a bad default value, since 403 means "Forbidden". Change any call to `error!` that does not specify a status code to specify one. The new default value is a more sensible default of 500, which is "Internal Server Error".
|
51
|
+
|
52
|
+
```ruby
|
53
|
+
error! "You may not reticulate this spline!", 403 # yields HTTP error 403
|
54
|
+
```
|
55
|
+
|
56
|
+
You may also use `default_error_status` to change the global default.
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
default_error_status 400
|
60
|
+
```
|
61
|
+
|
62
|
+
See [#525](https://github.com/intridea/Grape/pull/525) for more information.
|
63
|
+
|
64
|
+
|
65
|
+
#### Changes in Parameter Declaration and Validation
|
66
|
+
|
67
|
+
In Grape <= 0.6.1, `group`, `optional` and `requires` keywords with a block accepted either an `Array` or a `Hash`.
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
params do
|
71
|
+
requires :id, type: Integer
|
72
|
+
group :name do
|
73
|
+
requires :first_name
|
74
|
+
requires :last_name
|
75
|
+
end
|
76
|
+
end
|
77
|
+
```
|
78
|
+
|
79
|
+
This caused the ambiguity and unexpected errors described in [#543](https://github.com/intridea/Grape/issues/543).
|
80
|
+
|
81
|
+
In Grape 0.6.2, the `group`, `optional` and `requires` keywords take an additional `type` attribute which defaults to `Array`. This means that without a `type` attribute, these nested parameters will no longer accept a single hash, only an array (of hashes).
|
82
|
+
|
83
|
+
Whereas in 0.6.1 the API above accepted the following json, it no longer does in 0.6.2.
|
84
|
+
|
85
|
+
```json
|
86
|
+
{
|
87
|
+
"id": 1,
|
88
|
+
"name": {
|
89
|
+
"first_name": "John",
|
90
|
+
"last_name" : "Doe"
|
91
|
+
}
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
The `params` block should now read as follows.
|
96
|
+
|
97
|
+
```ruby
|
98
|
+
params do
|
99
|
+
requires :id, type: Integer
|
100
|
+
requires :name, type: Hash do
|
101
|
+
requires :first_name
|
102
|
+
requires :last_name
|
103
|
+
end
|
104
|
+
end
|
105
|
+
```
|
106
|
+
|
107
|
+
See [#545](https://github.com/intridea/Grape/pull/545) for more information.
|
108
|
+
|
109
|
+
|
110
|
+
### Upgrading to 0.6.0
|
111
|
+
|
112
|
+
In Grape <= 0.5.0, only the first validation error was raised and processing aborted. Validation errors are now collected and a single `Grape::Exceptions::ValidationErrors` exception is raised. You can access the collection of validation errors as `.errors`.
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
rescue_from Grape::Exceptions::Validations do |e|
|
116
|
+
Rack::Response.new({
|
117
|
+
status: 422,
|
118
|
+
message: e.message,
|
119
|
+
errors: e.errors
|
120
|
+
}.to_json, 422)
|
121
|
+
end
|
122
|
+
```
|
123
|
+
|
124
|
+
For more information see [#462](https://github.com/intridea/grape/issues/462).
|
data/grape.gemspec
CHANGED
@@ -14,14 +14,14 @@ Gem::Specification.new do |s|
|
|
14
14
|
|
15
15
|
s.rubyforge_project = "grape"
|
16
16
|
|
17
|
-
s.add_runtime_dependency 'rack'
|
17
|
+
s.add_runtime_dependency 'rack', '>= 1.3.0'
|
18
18
|
s.add_runtime_dependency 'rack-mount'
|
19
19
|
s.add_runtime_dependency 'rack-accept'
|
20
20
|
s.add_runtime_dependency 'activesupport'
|
21
21
|
s.add_runtime_dependency 'multi_json', '>= 1.3.2'
|
22
22
|
s.add_runtime_dependency 'multi_xml', '>= 0.5.2'
|
23
|
-
s.add_runtime_dependency 'hashie', '
|
24
|
-
s.add_runtime_dependency 'virtus'
|
23
|
+
s.add_runtime_dependency 'hashie', '>= 1.2.0'
|
24
|
+
s.add_runtime_dependency 'virtus', '>= 1.0.0'
|
25
25
|
s.add_runtime_dependency 'builder'
|
26
26
|
|
27
27
|
s.add_development_dependency 'grape-entity', '>= 0.2.0'
|