tomogram_routing 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/tomogram_routing/tomogram.rb +25 -13
- data/lib/tomogram_routing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcb98ad3fe017db262e35ca34c30ca89931bb531
|
4
|
+
data.tar.gz: 9b21414348bbd8649102e23018f3f320bc6edd0a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7929357cc86a34a0a9844990ffbe2cccbc66d92270ebfdded6e979bfce42b6d2b0c969d4062d989b0542b8c4d32a648221d8bb14b400401ea591bbc0f5482f70
|
7
|
+
data.tar.gz: d2bdf5d2624d84bc501d80210b27874716979a1f2ab94cac3b06eed8448c9af87758e4cdb6ce2f0e0228ad1a1a17b193e672285504b942193cd17845779b7a80
|
@@ -17,6 +17,27 @@ module TomogramRouting
|
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
|
+
def initialize(array)
|
21
|
+
super
|
22
|
+
compile_path_patterns
|
23
|
+
end
|
24
|
+
|
25
|
+
def compile_path_patterns
|
26
|
+
each do |action|
|
27
|
+
next unless (path = action['path'])
|
28
|
+
|
29
|
+
regexp = compile_path_pattern(path)
|
30
|
+
action['path_regexp'] = regexp
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def compile_path_pattern(path)
|
35
|
+
str = Regexp.escape(path)
|
36
|
+
str = str.gsub(/\\{\w+\\}/, '[^&=\/]+')
|
37
|
+
str = "\\A#{ str }\\z"
|
38
|
+
Regexp.new(str)
|
39
|
+
end
|
40
|
+
|
20
41
|
def find_request_path(method:, path:)
|
21
42
|
return '' unless path && path.size > 0
|
22
43
|
|
@@ -26,7 +47,7 @@ module TomogramRouting
|
|
26
47
|
return action['path'] if action
|
27
48
|
|
28
49
|
action = search_with_parameter(method, path, self)
|
29
|
-
return action['path'] if action
|
50
|
+
return action['path'] if action
|
30
51
|
|
31
52
|
''
|
32
53
|
end
|
@@ -53,13 +74,10 @@ module TomogramRouting
|
|
53
74
|
|
54
75
|
def search_with_parameter(method, path, documentation)
|
55
76
|
documentation = actions_with_same_method(documentation, method)
|
56
|
-
sought_for_path = path.split('/')
|
57
77
|
|
58
|
-
documentation.
|
59
|
-
|
60
|
-
|
61
|
-
next unless match(sought_for_path, current_path)
|
62
|
-
return action
|
78
|
+
documentation.find do |action|
|
79
|
+
next unless regexp = action['path_regexp']
|
80
|
+
regexp =~ path
|
63
81
|
end
|
64
82
|
end
|
65
83
|
|
@@ -68,11 +86,5 @@ module TomogramRouting
|
|
68
86
|
doc['method'] == method
|
69
87
|
end
|
70
88
|
end
|
71
|
-
|
72
|
-
def match(sought_for_path, current_path)
|
73
|
-
sought_for_path.zip(current_path).all? do |p|
|
74
|
-
p[0] == p[1] || (p[1][0] == '{' && p[1][-1] == '}')
|
75
|
-
end
|
76
|
-
end
|
77
89
|
end
|
78
90
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tomogram_routing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- d.efimov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-04-
|
11
|
+
date: 2017-04-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: multi_json
|