bbserver 0.2.0 → 0.3.0
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.
- checksums.yaml +4 -4
- data/lib/bbserver/context_locals.rb +1 -1
- data/lib/bbserver/route_registry.rb +49 -11
- data/lib/bbserver/router.rb +6 -2
- data/lib/bbserver/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 99665aa54be848e3c4fc6429586022214d4a2f2e12c743dd23ca4cac97582cce
|
|
4
|
+
data.tar.gz: 258ab27cb2a11c4379aa648dfff5e8dbec3e9a4e97062499fa293cd4ee66d1b3
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3e8ccc09aa06b5b86a773636f898f85280bee3e718d6f7241b1ccbdf70c5d635cc43b9c1db81217ac8c347bd067a7a3a7f2b19c30869d88573de4d20a074cd04
|
|
7
|
+
data.tar.gz: 5123fa56f4d9b285748c7d36ccc92c60565e783d4c3df44814f663de365efad5d5020cc631f13ceab8be2e56f2b32d5f03559d7df91e4efd888bc47aa3b0ee35
|
|
@@ -25,25 +25,63 @@ module BBServer
|
|
|
25
25
|
@routes.find(&:any?)
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
route = Route.new(method: http_verb.to_s.upcase, path: path, middlewares: @middlewares.dup)
|
|
32
|
-
@routes << route
|
|
33
|
-
route
|
|
34
|
-
end
|
|
28
|
+
def get(path)
|
|
29
|
+
raise_if_any_registered
|
|
30
|
+
register_route(:GET, path)
|
|
35
31
|
end
|
|
36
32
|
|
|
37
|
-
def
|
|
38
|
-
|
|
33
|
+
def post(path)
|
|
34
|
+
raise_if_any_registered
|
|
35
|
+
register_route(:POST, path)
|
|
39
36
|
end
|
|
40
37
|
|
|
41
|
-
def
|
|
42
|
-
|
|
38
|
+
def put(path)
|
|
39
|
+
raise_if_any_registered
|
|
40
|
+
register_route(:PUT, path)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def delete(path)
|
|
44
|
+
raise_if_any_registered
|
|
45
|
+
register_route(:DELETE, path)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
def patch(path)
|
|
49
|
+
raise_if_any_registered
|
|
50
|
+
register_route(:PATCH, path)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def head(path)
|
|
54
|
+
raise_if_any_registered
|
|
55
|
+
register_route(:HEAD, path)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def options(path)
|
|
59
|
+
raise_if_any_registered
|
|
60
|
+
register_route(:OPTIONS, path)
|
|
43
61
|
end
|
|
44
62
|
|
|
45
63
|
def list
|
|
46
64
|
@routes
|
|
47
65
|
end
|
|
66
|
+
|
|
67
|
+
def length
|
|
68
|
+
@routes.length
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
private
|
|
72
|
+
|
|
73
|
+
def raise_if_any_registered
|
|
74
|
+
raise RuntimeError, "Cannot register routes after ANY handler" if has_any?
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def register_route(method, path)
|
|
78
|
+
route = Route.new(method: method.to_s.upcase, path: path, middlewares: @middlewares.dup)
|
|
79
|
+
@routes << route
|
|
80
|
+
route
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
def find(path)
|
|
84
|
+
@routes.find { |r| r.path == path }
|
|
85
|
+
end
|
|
48
86
|
end
|
|
49
87
|
end
|
data/lib/bbserver/router.rb
CHANGED
|
@@ -29,15 +29,19 @@ module BBServer
|
|
|
29
29
|
|
|
30
30
|
next unless route.method == method
|
|
31
31
|
|
|
32
|
-
|
|
32
|
+
route_path = route.path
|
|
33
|
+
next unless route_path.is_a?(String)
|
|
34
|
+
parts = route_path.split('/')
|
|
33
35
|
path_parts = path.split('/')
|
|
34
36
|
|
|
35
37
|
next unless parts.size == path_parts.size
|
|
36
38
|
|
|
39
|
+
# @type var params: Hash[Symbol, String]
|
|
37
40
|
params = {}
|
|
38
41
|
match = parts.each_with_index.all? do |part, i|
|
|
39
42
|
if part.start_with?(':')
|
|
40
|
-
|
|
43
|
+
part_name = part[1..-1]
|
|
44
|
+
params[part_name.to_sym] = path_parts[i] if part_name
|
|
41
45
|
true
|
|
42
46
|
else
|
|
43
47
|
part == path_parts[i]
|
data/lib/bbserver/version.rb
CHANGED