strong_routes 0.9.5 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c949ed86bf9856ae47f55db3b94ffe96ba990331
|
4
|
+
data.tar.gz: ee565e1289a1cb7bb38371ebb33d33b68acc94a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f79c6760a315f0c1b75a1af6e55b88837be7bc8276581dba273597b95e66e830859541e5988fab3c87c3f4711df61b20b27646c6b130f5722c5715b7339de114
|
7
|
+
data.tar.gz: e590063892de6bd092eaad914c0e2e6618d67cd9ddc0c4154550eddaa3e037c0c01f0410df3a883130d2c85305130cc87069f49fdfab067030a804517c4ad3e9
|
@@ -19,15 +19,15 @@ module StrongRoutes
|
|
19
19
|
map = matches.map { |match_data| match_data[:path] }
|
20
20
|
map.compact!
|
21
21
|
map.uniq!
|
22
|
+
map
|
22
23
|
end
|
23
24
|
|
24
25
|
private
|
25
26
|
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# match data objects.
|
27
|
+
# Convert the path strings into match data objects, capturing all segments
|
28
|
+
# except optional ones (e.g. :format).
|
29
29
|
def matches
|
30
|
-
matches = paths.map { |path| path.match(/\A\/(?<path>[
|
30
|
+
matches = paths.map { |path| path.match(/\A\/(?<path>[-:\w\/]+)\/*.*\Z/) }
|
31
31
|
matches.compact!
|
32
32
|
matches.uniq!
|
33
33
|
matches
|
@@ -4,8 +4,28 @@ module StrongRoutes
|
|
4
4
|
if route.is_a?(Regexp)
|
5
5
|
super(route)
|
6
6
|
else
|
7
|
-
|
7
|
+
route = map_dynamic_segments(route)
|
8
|
+
escaped_route = Regexp.escape(route)
|
9
|
+
super(/\A\/#{route}/i)
|
8
10
|
end
|
9
11
|
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
# Replace dynamic segments in the route with wildcards (e.g. /:foo/users/:id
|
16
|
+
# becomes /.*/users/.*)
|
17
|
+
#
|
18
|
+
def map_dynamic_segments(route)
|
19
|
+
segments = route.to_s.split('/')
|
20
|
+
segments.map! do |segment|
|
21
|
+
if segment =~ /:/
|
22
|
+
'.*'
|
23
|
+
else
|
24
|
+
segment
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
segments.join('/')
|
29
|
+
end
|
10
30
|
end
|
11
31
|
end
|
@@ -4,7 +4,22 @@ require 'action_dispatch'
|
|
4
4
|
require 'strong_routes/rails/route_mapper'
|
5
5
|
|
6
6
|
describe ::StrongRoutes::Rails::RouteMapper do
|
7
|
-
let(:paths) {
|
7
|
+
let(:paths) {
|
8
|
+
[
|
9
|
+
'bar/sandwich',
|
10
|
+
'comments/:id',
|
11
|
+
'comments/:id/edit',
|
12
|
+
'posts/:id',
|
13
|
+
'posts/:id/edit',
|
14
|
+
'posts/:post_id/comments',
|
15
|
+
'posts/:post_id/comments/new',
|
16
|
+
'trading-post',
|
17
|
+
'user_posts/:id',
|
18
|
+
'users',
|
19
|
+
'users/:user_id/posts',
|
20
|
+
'users/:user_id/posts/new'
|
21
|
+
]
|
22
|
+
}
|
8
23
|
let(:route_set) {
|
9
24
|
route_set = ActionDispatch::Routing::RouteSet.new
|
10
25
|
route_set.draw do
|
@@ -12,7 +12,7 @@ describe ::StrongRoutes::RouteMatcher do
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
context "when
|
15
|
+
context "when given a symbol" do
|
16
16
|
let(:matcher) { /\A\/foo/i }
|
17
17
|
|
18
18
|
subject { ::StrongRoutes::RouteMatcher.new(:foo) }
|
@@ -22,7 +22,7 @@ describe ::StrongRoutes::RouteMatcher do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
context "when
|
25
|
+
context "when given a string" do
|
26
26
|
let(:matcher) { /\A\/foo/i }
|
27
27
|
|
28
28
|
subject { ::StrongRoutes::RouteMatcher.new('foo') }
|
@@ -31,5 +31,15 @@ describe ::StrongRoutes::RouteMatcher do
|
|
31
31
|
subject.must_equal matcher
|
32
32
|
end
|
33
33
|
end
|
34
|
+
|
35
|
+
context "when given a string with dynamic segments" do
|
36
|
+
let(:matcher) { /\A\/.*\/foo\/.*\/bar/i }
|
37
|
+
|
38
|
+
subject { ::StrongRoutes::RouteMatcher.new(':id/foo/:foo_id/bar') }
|
39
|
+
|
40
|
+
it "creates a new matcher" do
|
41
|
+
subject.must_equal matcher
|
42
|
+
end
|
43
|
+
end
|
34
44
|
end
|
35
45
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: strong_routes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hutchison
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03
|
11
|
+
date: 2014-04-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -150,9 +150,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
150
|
version: '0'
|
151
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
152
|
requirements:
|
153
|
-
- - '
|
153
|
+
- - '>'
|
154
154
|
- !ruby/object:Gem::Version
|
155
|
-
version:
|
155
|
+
version: 1.3.1
|
156
156
|
requirements: []
|
157
157
|
rubyforge_project:
|
158
158
|
rubygems_version: 2.2.2
|