-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support ruby 2.4 #1543
Merged
Merged
Support ruby 2.4 #1543
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
- [Include Missing](#include-missing) | ||
- [Parameter Validation and Coercion](#parameter-validation-and-coercion) | ||
- [Supported Parameter Types](#supported-parameter-types) | ||
- [Integer/Fixnum and Coercions](#integerfixnum-and-coercions) | ||
- [Custom Types and Coercions](#custom-types-and-coercions) | ||
- [Multipart File Parameters](#multipart-file-parameters) | ||
- [First-Class `JSON` Types](#first-class-json-types) | ||
|
@@ -799,6 +800,28 @@ The following are all valid types, supported out of the box by Grape: | |
* Rack::Multipart::UploadedFile (alias `File`) | ||
* JSON | ||
|
||
### Integer/Fixnum and Coercions | ||
|
||
Please be aware that the behavior differs between Ruby 2.4 and earlier versions. | ||
In Ruby 2.4, values consisting of numbers are converted to Integer, but in earlier versions it will be treated as Fixnum. | ||
|
||
```ruby | ||
params do | ||
requires :integers, type: Hash do | ||
requires :int, coerce: Integer | ||
end | ||
end | ||
get '/int' do | ||
params[:integers][:int].class | ||
end | ||
|
||
... | ||
|
||
get '/int' integers: { int: '45' } | ||
#=> Integer in ruby 2.4 | ||
#=> Fixnum in earlier ruby versions | ||
``` | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added Integer/Fixnum and Corcions section. Could you review this ? |
||
### Custom Types and Coercions | ||
|
||
Aside from the default set of supported types listed above, any class can be | ||
|
@@ -2878,7 +2901,7 @@ end | |
The behaviour is then: | ||
|
||
```bash | ||
GET /123 # 'Fixnum' | ||
GET /123 # 'Integer' | ||
GET /foo # 400 error - 'blah is invalid' | ||
``` | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
def encode_basic_auth(username, password) | ||
'Basic ' + Base64.encode64("#{username}:#{password}") | ||
module Spec | ||
module Support | ||
module Helpers | ||
def encode_basic_auth(username, password) | ||
'Basic ' + Base64.encode64("#{username}:#{password}") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
module ContentTypeHelpers | ||
%w(put patch post delete).each do |method| | ||
define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block| | ||
params = params.to_json | ||
env['CONTENT_TYPE'] ||= 'application/json' | ||
send(method, uri, params, env, &block) | ||
module Spec | ||
module Support | ||
module Helpers | ||
%w(put patch post delete).each do |method| | ||
define_method :"#{method}_with_json" do |uri, params = {}, env = {}, &block| | ||
params = params.to_json | ||
env['CONTENT_TYPE'] ||= 'application/json' | ||
send(method, uri, params, env, &block) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
include(ContentTypeHelpers) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module Spec | ||
module Support | ||
module Helpers | ||
INTEGER_CLASS_NAME = 0.to_i.class.to_s.freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How clever! |
||
|
||
def integer_class_name | ||
INTEGER_CLASS_NAME | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added @LeFnord .