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.
- checksums.yaml +4 -4
- data/Appraisals +9 -4
- data/CHANGELOG.md +28 -0
- data/Gemfile +0 -1
- data/Gemfile.lock +166 -0
- data/README.md +305 -163
- data/Rakefile +30 -33
- data/UPGRADING.md +31 -0
- data/benchmark/simple.rb +27 -0
- data/gemfiles/rack_1.5.2.gemfile +13 -0
- data/gemfiles/rails_3.gemfile +2 -2
- data/gemfiles/rails_4.gemfile +1 -2
- data/grape.gemspec +5 -4
- data/lib/grape.rb +9 -5
- data/lib/grape/dsl/configuration.rb +5 -2
- data/lib/grape/dsl/helpers.rb +8 -3
- data/lib/grape/dsl/inside_route.rb +67 -44
- data/lib/grape/dsl/parameters.rb +21 -12
- data/lib/grape/dsl/request_response.rb +1 -1
- data/lib/grape/dsl/routing.rb +3 -4
- data/lib/grape/endpoint.rb +63 -28
- data/lib/grape/error_formatter/base.rb +6 -6
- data/lib/grape/exceptions/base.rb +5 -5
- data/lib/grape/exceptions/invalid_version_header.rb +10 -0
- data/lib/grape/formatter/serializable_hash.rb +3 -2
- data/lib/grape/locale/en.yml +4 -1
- data/lib/grape/middleware/auth/base.rb +2 -2
- data/lib/grape/middleware/auth/dsl.rb +1 -1
- data/lib/grape/middleware/auth/strategies.rb +1 -1
- data/lib/grape/middleware/base.rb +7 -4
- data/lib/grape/middleware/error.rb +3 -2
- data/lib/grape/middleware/filter.rb +1 -1
- data/lib/grape/middleware/formatter.rb +47 -44
- data/lib/grape/middleware/globals.rb +3 -3
- data/lib/grape/middleware/versioner/accept_version_header.rb +5 -7
- data/lib/grape/middleware/versioner/header.rb +113 -50
- data/lib/grape/middleware/versioner/param.rb +5 -8
- data/lib/grape/middleware/versioner/parse_media_type_patch.rb +20 -0
- data/lib/grape/middleware/versioner/path.rb +3 -6
- data/lib/grape/path.rb +3 -3
- data/lib/grape/request.rb +40 -0
- data/lib/grape/util/content_types.rb +9 -9
- data/lib/grape/util/env.rb +22 -0
- data/lib/grape/util/strict_hash_configuration.rb +2 -1
- data/lib/grape/validations/attributes_iterator.rb +8 -3
- data/lib/grape/validations/params_scope.rb +83 -15
- data/lib/grape/validations/types.rb +144 -0
- data/lib/grape/validations/types/build_coercer.rb +53 -0
- data/lib/grape/validations/types/custom_type_coercer.rb +183 -0
- data/lib/grape/validations/types/file.rb +28 -0
- data/lib/grape/validations/types/json.rb +65 -0
- data/lib/grape/validations/types/multiple_type_coercer.rb +76 -0
- data/lib/grape/validations/types/variant_collection_coercer.rb +59 -0
- data/lib/grape/validations/types/virtus_collection_patch.rb +16 -0
- data/lib/grape/validations/validators/all_or_none.rb +1 -1
- data/lib/grape/validations/validators/allow_blank.rb +3 -3
- data/lib/grape/validations/validators/base.rb +7 -0
- data/lib/grape/validations/validators/coerce.rb +31 -42
- data/lib/grape/validations/validators/presence.rb +2 -3
- data/lib/grape/validations/validators/regexp.rb +2 -4
- data/lib/grape/validations/validators/values.rb +3 -3
- data/lib/grape/version.rb +1 -1
- data/pkg/grape-0.13.0.gem +0 -0
- data/spec/grape/api/custom_validations_spec.rb +5 -4
- data/spec/grape/api/deeply_included_options_spec.rb +7 -7
- data/spec/grape/api/nested_helpers_spec.rb +4 -2
- data/spec/grape/api/shared_helpers_spec.rb +8 -8
- data/spec/grape/api_spec.rb +88 -54
- data/spec/grape/dsl/configuration_spec.rb +13 -0
- data/spec/grape/dsl/helpers_spec.rb +16 -2
- data/spec/grape/dsl/inside_route_spec.rb +3 -2
- data/spec/grape/dsl/parameters_spec.rb +0 -6
- data/spec/grape/dsl/routing_spec.rb +1 -1
- data/spec/grape/endpoint_spec.rb +61 -20
- data/spec/grape/entity_spec.rb +10 -8
- data/spec/grape/exceptions/invalid_accept_header_spec.rb +1 -15
- data/spec/grape/integration/rack_spec.rb +3 -2
- data/spec/grape/middleware/base_spec.rb +7 -5
- data/spec/grape/middleware/error_spec.rb +16 -15
- data/spec/grape/middleware/exception_spec.rb +45 -43
- data/spec/grape/middleware/formatter_spec.rb +34 -0
- data/spec/grape/middleware/versioner/header_spec.rb +79 -47
- data/spec/grape/path_spec.rb +10 -10
- data/spec/grape/presenters/presenter_spec.rb +2 -2
- data/spec/grape/request_spec.rb +100 -0
- data/spec/grape/validations/params_scope_spec.rb +11 -9
- data/spec/grape/validations/types_spec.rb +95 -0
- data/spec/grape/validations/validators/coerce_spec.rb +335 -2
- data/spec/grape/validations/validators/values_spec.rb +15 -15
- data/spec/grape/validations_spec.rb +53 -24
- data/spec/shared/versioning_examples.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/support/versioned_helpers.rb +2 -2
- metadata +51 -13
- data/.gitignore +0 -46
- data/.rspec +0 -2
- data/.rubocop.yml +0 -7
- data/.rubocop_todo.yml +0 -84
- data/.travis.yml +0 -20
- data/.yardopts +0 -2
- data/lib/grape/http/request.rb +0 -35
- data/lib/grape/util/parameter_types.rb +0 -58
- 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
data/.rubocop.yml
DELETED
data/.rubocop_todo.yml
DELETED
@@ -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
|
data/.travis.yml
DELETED
@@ -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
data/lib/grape/http/request.rb
DELETED
@@ -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
|