tomogram_routing 0.1.4 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3abd7983bdf67aa0314618cc9690576dc4daf407
4
- data.tar.gz: cbad40f31afad50c16bc533affbe3f44bca63edd
3
+ metadata.gz: bcb98ad3fe017db262e35ca34c30ca89931bb531
4
+ data.tar.gz: 9b21414348bbd8649102e23018f3f320bc6edd0a
5
5
  SHA512:
6
- metadata.gz: 896bfa61bb0a81b93796d1333494e0456852691a59715c11f2d14ec5e77624095387b08e46c6c44e8d8d9798ea344c919988fb6f793b2b30873fddbb983e29f6
7
- data.tar.gz: dc2f4a2805945ac1218181edceb70d29a1030459cac975572124800b3aa963f7af132bda9f6399eb218fd21182472906a132ff68875d4ed8553cbd160fd8f5ae
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 && action.first
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.map do |action|
59
- current_path = action['path'].split('/')
60
- next unless sought_for_path.size == current_path.size
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
@@ -1,3 +1,3 @@
1
1
  module TomogramRouting
2
- VERSION = '0.1.4'.freeze
2
+ VERSION = '0.1.5'.freeze
3
3
  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
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-06 00:00:00.000000000 Z
11
+ date: 2017-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: multi_json