soar_sc-rack-router 1.0.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -0
- data/lib/soar_sc/rack/router/route.rb +32 -16
- data/lib/soar_sc/rack/router/version.rb +1 -1
- data/lib/soar_sc/rack/router.rb +4 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c3e14ae23f2f9217563a57239e82ec930382ec1
|
4
|
+
data.tar.gz: 6ab1b6bf12582996334481f2aa06a90cb0447c55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1593840d3ea7254eb74ce64dd95bf8d3ea2a984821117bd3a802da50a81ef8b5cdc71a66c3d1aca4b4b57d517498456d2753f7ed53ce696c0ee33fbeb7aecc17
|
7
|
+
data.tar.gz: c0572f514f065db5b65dd22a841459323899a49f186ccf0f3f7242c739ccf7ba475dd7de13ced12dcb257d84c6feba783c51ed86790155b66ba0a9b8f49262db
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/soar_sc-rack-router.svg)](http://badge.fury.io/rb/soar_sc-rack-router) [![Build Status](https://travis-ci.org/hetznerZA/soar_sc-rack-router.svg?branch=master)](https://travis-ci.org/hetznerZA/soar_sc-rack-router)
|
2
|
+
|
1
3
|
# SoarSc::Rack::Router
|
2
4
|
|
3
5
|
SoarSc::Rack::Router is a middleware-centric rack router. It has three key features:
|
@@ -18,24 +18,11 @@ module SoarSc
|
|
18
18
|
def initialize(method, path, action)
|
19
19
|
validate_path(path)
|
20
20
|
@method, @path, @action = method, path, action
|
21
|
-
@static = components(path).none? { |c| c.start_with?(PARAMETER_PREFIX) }
|
21
|
+
@static = components(@path).none? { |c| c.start_with?(PARAMETER_PREFIX) }
|
22
22
|
end
|
23
23
|
|
24
24
|
def matches?(env)
|
25
|
-
|
26
|
-
|
27
|
-
return request_path(env) == path if @static
|
28
|
-
|
29
|
-
route_components = components(path)
|
30
|
-
req_components = components(request_path(env))
|
31
|
-
|
32
|
-
return false unless route_components.size == req_components.size
|
33
|
-
|
34
|
-
route_components.each_with_index do |c, i|
|
35
|
-
return false unless c.start_with?(PARAMETER_PREFIX) or c == req_components[i]
|
36
|
-
end
|
37
|
-
|
38
|
-
return true
|
25
|
+
method_matches?(env[REQUEST_METHOD]) and path_matches?(request_path(env))
|
39
26
|
end
|
40
27
|
|
41
28
|
def extract_path_parameters(env)
|
@@ -43,7 +30,7 @@ module SoarSc
|
|
43
30
|
|
44
31
|
req_components = components(request_path(env))
|
45
32
|
parameters = {}
|
46
|
-
components(path).each_with_index do |c, i|
|
33
|
+
components(@path).each_with_index do |c, i|
|
47
34
|
parameters[c[1..-1]] = req_components[i] if c.start_with?(PARAMETER_PREFIX)
|
48
35
|
end
|
49
36
|
parameters
|
@@ -51,6 +38,35 @@ module SoarSc
|
|
51
38
|
|
52
39
|
private
|
53
40
|
|
41
|
+
def method_matches?(method)
|
42
|
+
@method == method or @method == HttpMethod::ANY
|
43
|
+
end
|
44
|
+
|
45
|
+
def path_matches?(path)
|
46
|
+
if @static
|
47
|
+
static_path_matches?(path)
|
48
|
+
else
|
49
|
+
parameterized_path_matches?(path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def static_path_matches?(path)
|
54
|
+
path == @path
|
55
|
+
end
|
56
|
+
|
57
|
+
def parameterized_path_matches?(path)
|
58
|
+
route_components = components(@path)
|
59
|
+
req_components = components(path)
|
60
|
+
|
61
|
+
return false unless route_components.size == req_components.size
|
62
|
+
|
63
|
+
route_components.each_with_index do |c, i|
|
64
|
+
return false unless c.start_with?(PARAMETER_PREFIX) or c == req_components[i]
|
65
|
+
end
|
66
|
+
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
|
54
70
|
def request_path(env)
|
55
71
|
env[SCRIPT_NAME] + env[PATH_INFO]
|
56
72
|
end
|
data/lib/soar_sc/rack/router.rb
CHANGED
@@ -14,10 +14,12 @@ module SoarSc
|
|
14
14
|
|
15
15
|
EMPTY_STRING = ""
|
16
16
|
|
17
|
-
def initialize(app, routes =
|
17
|
+
def initialize(app, routes = nil, &block)
|
18
18
|
@app = app
|
19
19
|
@routes = []
|
20
|
-
routes.
|
20
|
+
if !routes.nil?
|
21
|
+
raise NotImplementedError, "Route map syntax obsoleted (use builder syntax)"
|
22
|
+
end
|
21
23
|
instance_eval(&block) if block_given?
|
22
24
|
end
|
23
25
|
|