grape 0.12.0 → 0.13.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/.rubocop_todo.yml +2 -2
- data/CHANGELOG.md +237 -215
- data/CONTRIBUTING.md +4 -4
- data/README.md +133 -10
- data/RELEASING.md +14 -6
- data/Rakefile +1 -1
- data/UPGRADING.md +23 -23
- data/grape.gemspec +1 -3
- data/lib/grape/api.rb +24 -4
- data/lib/grape/dsl/callbacks.rb +20 -0
- data/lib/grape/dsl/configuration.rb +54 -0
- data/lib/grape/dsl/inside_route.rb +33 -1
- data/lib/grape/dsl/parameters.rb +80 -0
- data/lib/grape/dsl/routing.rb +14 -0
- data/lib/grape/dsl/settings.rb +36 -1
- data/lib/grape/dsl/validations.rb +7 -5
- data/lib/grape/endpoint.rb +42 -32
- data/lib/grape/exceptions/unknown_parameter.rb +10 -0
- data/lib/grape/exceptions/validation_errors.rb +4 -3
- data/lib/grape/http/headers.rb +0 -1
- data/lib/grape/http/request.rb +12 -4
- data/lib/grape/locale/en.yml +1 -0
- data/lib/grape/middleware/base.rb +1 -0
- data/lib/grape/middleware/formatter.rb +39 -23
- data/lib/grape/namespace.rb +13 -2
- data/lib/grape/path.rb +1 -0
- data/lib/grape/route.rb +5 -0
- data/lib/grape/util/file_response.rb +21 -0
- data/lib/grape/util/inheritable_setting.rb +23 -2
- data/lib/grape/util/inheritable_values.rb +1 -1
- data/lib/grape/util/parameter_types.rb +58 -0
- data/lib/grape/util/stackable_values.rb +5 -2
- data/lib/grape/validations/params_scope.rb +83 -9
- data/lib/grape/validations/validators/coerce.rb +11 -2
- data/lib/grape/validations.rb +5 -0
- data/lib/grape/version.rb +2 -1
- data/lib/grape.rb +7 -8
- data/spec/grape/api_spec.rb +63 -0
- data/spec/grape/dsl/inside_route_spec.rb +37 -2
- data/spec/grape/dsl/validations_spec.rb +18 -0
- data/spec/grape/endpoint_spec.rb +83 -0
- data/spec/grape/exceptions/validation_errors_spec.rb +28 -0
- data/spec/grape/middleware/base_spec.rb +33 -11
- data/spec/grape/middleware/formatter_spec.rb +0 -5
- data/spec/grape/util/inheritable_values_spec.rb +14 -0
- data/spec/grape/util/parameter_types_spec.rb +54 -0
- data/spec/grape/util/stackable_values_spec.rb +10 -0
- data/spec/grape/validations/params_scope_spec.rb +84 -0
- data/spec/grape/validations/validators/coerce_spec.rb +29 -8
- data/spec/grape/validations/validators/values_spec.rb +12 -0
- metadata +9 -6
- data/lib/backports/active_support/deep_dup.rb +0 -49
- data/lib/backports/active_support/duplicable.rb +0 -88
@@ -1,88 +0,0 @@
|
|
1
|
-
# Backport from Rails 4.x
|
2
|
-
# https://github.com/rails/rails/blob/4-0-stable/activesupport/lib/active_support/core_ext/object/deep_dup.rb
|
3
|
-
|
4
|
-
#--
|
5
|
-
# Most objects are cloneable, but not all. For example you can't dup +nil+:
|
6
|
-
#
|
7
|
-
# nil.dup # => TypeError: can't dup NilClass
|
8
|
-
#
|
9
|
-
# Classes may signal their instances are not duplicable removing +dup+/+clone+
|
10
|
-
# or raising exceptions from them. So, to dup an arbitrary object you normally
|
11
|
-
# use an optimistic approach and are ready to catch an exception, say:
|
12
|
-
#
|
13
|
-
# arbitrary_object.dup rescue object
|
14
|
-
#
|
15
|
-
# Rails dups objects in a few critical spots where they are not that arbitrary.
|
16
|
-
# That rescue is very expensive (like 40 times slower than a predicate), and it
|
17
|
-
# is often triggered.
|
18
|
-
#
|
19
|
-
# That's why we hardcode the following cases and check duplicable? instead of
|
20
|
-
# using that rescue idiom.
|
21
|
-
#++
|
22
|
-
class Object
|
23
|
-
# Can you safely dup this object?
|
24
|
-
#
|
25
|
-
# False for +nil+, +false+, +true+, symbol, and number objects;
|
26
|
-
# true otherwise.
|
27
|
-
def duplicable?
|
28
|
-
true
|
29
|
-
end
|
30
|
-
end
|
31
|
-
class NilClass
|
32
|
-
# +nil+ is not duplicable:
|
33
|
-
#
|
34
|
-
# nil.duplicable? # => false
|
35
|
-
# nil.dup # => TypeError: can't dup NilClass
|
36
|
-
def duplicable?
|
37
|
-
false
|
38
|
-
end
|
39
|
-
end
|
40
|
-
class FalseClass
|
41
|
-
# +false+ is not duplicable:
|
42
|
-
#
|
43
|
-
# false.duplicable? # => false
|
44
|
-
# false.dup # => TypeError: can't dup FalseClass
|
45
|
-
def duplicable?
|
46
|
-
false
|
47
|
-
end
|
48
|
-
end
|
49
|
-
class TrueClass
|
50
|
-
# +true+ is not duplicable:
|
51
|
-
#
|
52
|
-
# true.duplicable? # => false
|
53
|
-
# true.dup # => TypeError: can't dup TrueClass
|
54
|
-
def duplicable?
|
55
|
-
false
|
56
|
-
end
|
57
|
-
end
|
58
|
-
class Symbol
|
59
|
-
# Symbols are not duplicable:
|
60
|
-
#
|
61
|
-
# :my_symbol.duplicable? # => false
|
62
|
-
# :my_symbol.dup # => TypeError: can't dup Symbol
|
63
|
-
def duplicable?
|
64
|
-
false
|
65
|
-
end
|
66
|
-
end
|
67
|
-
class Numeric
|
68
|
-
# Numbers are not duplicable:
|
69
|
-
#
|
70
|
-
# 3.duplicable? # => false
|
71
|
-
# 3.dup # => TypeError: can't dup Fixnum
|
72
|
-
def duplicable?
|
73
|
-
false
|
74
|
-
end
|
75
|
-
end
|
76
|
-
require 'bigdecimal'
|
77
|
-
# rubocop:disable Lint/HandleExceptions
|
78
|
-
class BigDecimal
|
79
|
-
begin
|
80
|
-
BigDecimal.new('4.56').dup
|
81
|
-
def duplicable?
|
82
|
-
true
|
83
|
-
end
|
84
|
-
rescue TypeError
|
85
|
-
# can't dup, so use superclass implementation
|
86
|
-
end
|
87
|
-
end
|
88
|
-
# rubocop:enable Lint/HandleExceptions
|