committee 1.0.4 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/committee/router.rb +19 -9
- metadata +1 -1
data/lib/committee/router.rb
CHANGED
@@ -24,17 +24,27 @@ module Committee
|
|
24
24
|
|
25
25
|
def build_routes(schema)
|
26
26
|
routes = {}
|
27
|
-
|
28
|
-
schema.
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
|
28
|
+
schema.links.each do |link|
|
29
|
+
method, href = parse_link(link)
|
30
|
+
routes[method] ||= []
|
31
|
+
routes[method] << [%r{^#{href}$}, link]
|
32
|
+
end
|
33
|
+
|
34
|
+
# recursively iterate through all `properties` subschemas to build a
|
35
|
+
# complete routing table
|
36
|
+
schema.properties.each do |_, subschema|
|
37
|
+
routes.merge!(build_routes(subschema)) { |_, r1, r2| r1 + r2 }
|
36
38
|
end
|
39
|
+
|
37
40
|
routes
|
38
41
|
end
|
42
|
+
|
43
|
+
def parse_link(link)
|
44
|
+
method = link.method.to_s.upcase
|
45
|
+
# /apps/{id} --> /apps/([^/]+)
|
46
|
+
href = link.href.gsub(/\{(.*?)\}/, "[^/]+")
|
47
|
+
[method, href]
|
48
|
+
end
|
39
49
|
end
|
40
50
|
end
|