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: 0b15e31fe4c1c99b2dae4003285ebe54fa57af7f
4
- data.tar.gz: 2df7a6c037ab27aedb53062c8791554a02287e73
3
+ metadata.gz: c949ed86bf9856ae47f55db3b94ffe96ba990331
4
+ data.tar.gz: ee565e1289a1cb7bb38371ebb33d33b68acc94a9
5
5
  SHA512:
6
- metadata.gz: 352a1c740e090c13a9c38694267751b410af4083e938b233d3d74f8b809defb161adb1c249c896ad8e5ae5b02bf1888d968d212dd569ad9ebd46951c897be032
7
- data.tar.gz: 23f4690f909af7020d1a3b1c2a2d89b7bc37676f38d33f217ae116c89f56a25c06af4222674dc48c3fd0db9b9606a86834749f304e7b2c3d91673896a76011fe
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
- # All we need for the allowed routes is the first segment (i.e. 'users'
27
- # from '/users/:user_id/posts(/:format)'). Convert the path strings into
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>[\w-]+)\/*.*\Z/) }
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
- super(/\A\/#{route}/i,)
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
@@ -1,3 +1,3 @@
1
1
  module StrongRoutes
2
- VERSION = "0.9.5"
2
+ VERSION = "1.0.0.rc1"
3
3
  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) { [ 'users', 'posts', 'comments', 'user_posts', 'bar', 'trading-post' ] }
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 not given a symbol" do
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 not given a string" do
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.9.5
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-31 00:00:00.000000000 Z
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: '0'
155
+ version: 1.3.1
156
156
  requirements: []
157
157
  rubyforge_project:
158
158
  rubygems_version: 2.2.2