committee 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/committee/router.rb +19 -9
  2. metadata +1 -1
@@ -24,17 +24,27 @@ module Committee
24
24
 
25
25
  def build_routes(schema)
26
26
  routes = {}
27
- # realistically, we should be examining links recursively at all levels
28
- schema.properties.each do |_, type_schema|
29
- type_schema.links.each do |link|
30
- method = link.method.to_s.upcase
31
- routes[method] ||= []
32
- # /apps/{id} --> /apps/([^/]+)
33
- href = link.href.gsub(/\{(.*?)\}/, "[^/]+")
34
- routes[method] << [%r{^#{href}$}, link]
35
- end
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: committee
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: