File tree 3 files changed +26
-16
lines changed
3 files changed +26
-16
lines changed Original file line number Diff line number Diff line change @@ -13,8 +13,8 @@ class << self
13
13
14
14
# Clears all defined routes, endpoints, etc., on this API.
15
15
def reset!
16
- @endpoints = [ ]
17
- @routes = nil
16
+ reset_endpoints!
17
+ reset_routes!
18
18
reset_validations!
19
19
end
20
20
@@ -43,20 +43,10 @@ def call!(env)
43
43
instance . call ( env )
44
44
end
45
45
46
- # Create a scope without affecting the URL.
47
- #
48
- # @param _name [Symbol] Purely placebo, just allows to name the scope to
49
- # make the code more readable.
50
- def scope ( _name = nil , &block )
51
- within_namespace do
52
- nest ( block )
53
- end
54
- end
55
-
56
46
# (see #cascade?)
57
47
def cascade ( value = nil )
58
48
if value . nil?
59
- inheritable_setting . namespace_inheritable . keys . include? ( :cascade ) ? !! namespace_inheritable ( :cascade ) : true
49
+ inheritable_setting . namespace_inheritable . keys . include? ( :cascade ) ? !namespace_inheritable ( :cascade ) . nil? : true
60
50
else
61
51
namespace_inheritable ( :cascade , value )
62
52
end
@@ -90,9 +80,7 @@ def inherited(subclass)
90
80
def inherit_settings ( other_settings )
91
81
top_level_setting . inherit_from other_settings . point_in_time_copy
92
82
93
- endpoints . each ( &:reset_routes! )
94
-
95
- @routes = nil
83
+ reset_routes!
96
84
end
97
85
end
98
86
Original file line number Diff line number Diff line change @@ -58,6 +58,16 @@ def prefix(prefix = nil)
58
58
namespace_inheritable ( :root_prefix , prefix )
59
59
end
60
60
61
+ # Create a scope without affecting the URL.
62
+ #
63
+ # @param _name [Symbol] Purely placebo, just allows to name the scope to
64
+ # make the code more readable.
65
+ def scope ( _name = nil , &block )
66
+ within_namespace do
67
+ nest ( block )
68
+ end
69
+ end
70
+
61
71
# Do not route HEAD requests to GET requests automatically.
62
72
def do_not_route_head!
63
73
namespace_inheritable ( :do_not_route_head , true )
@@ -175,9 +185,14 @@ def routes
175
185
176
186
# Remove all defined routes.
177
187
def reset_routes!
188
+ endpoints . each ( &:reset_routes! )
178
189
@routes = nil
179
190
end
180
191
192
+ def reset_endpoints!
193
+ @endpoints = [ ]
194
+ end
195
+
181
196
# Thie method allows you to quickly define a parameter route segment
182
197
# in your API.
183
198
#
Original file line number Diff line number Diff line change @@ -31,6 +31,13 @@ class Dummy
31
31
end
32
32
end
33
33
34
+ describe '.scope' do
35
+ it 'create a scope without affecting the URL' do
36
+ expect ( subject ) . to receive ( :within_namespace )
37
+ subject . scope { }
38
+ end
39
+ end
40
+
34
41
describe '.do_not_route_head!' do
35
42
it 'sets do not route head option' do
36
43
expect ( subject ) . to receive ( :namespace_inheritable ) . with ( :do_not_route_head , true )
You can’t perform that action at this time.
0 commit comments