journey 1.0.0.rc2 → 1.0.0.rc3

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.
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  rvm:
2
2
  - 1.8.7
3
3
  - 1.9.2
4
+ - 1.9.3
4
5
  - jruby
5
6
  - rbx
6
7
  - ree
data/journey.gemspec CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "journey"
5
- s.version = "1.0.0.rc2.20111221114756"
5
+ s.version = "1.0.0.rc3.20111222185342"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Aaron Patterson"]
9
- s.date = "2011-12-21"
9
+ s.date = "2011-12-23"
10
10
  s.description = "Journey is a router. It routes requests."
11
11
  s.email = ["aaron@tenderlovemaking.com"]
12
12
  s.extra_rdoc_files = ["Manifest.txt", "CHANGELOG.rdoc", "README.rdoc"]
@@ -10,8 +10,8 @@ module Journey
10
10
  def initialize
11
11
  @regexp_states = Hash.new { |h,k| h[k] = {} }
12
12
  @string_states = Hash.new { |h,k| h[k] = {} }
13
- @accepting = {}
14
- @memos = Hash.new { |h,k| h[k] = [] }
13
+ @accepting = {}
14
+ @memos = Hash.new { |h,k| h[k] = [] }
15
15
  end
16
16
 
17
17
  def add_accepting state
@@ -103,8 +103,7 @@ module Journey
103
103
  return @separator_re unless @matchers.key? node
104
104
 
105
105
  re = @matchers[node]
106
- # FIXME: is the question mark needed?
107
- "(#{re}?)"
106
+ "(#{re})"
108
107
  end
109
108
 
110
109
  def visit_GROUP node
@@ -121,7 +120,8 @@ module Journey
121
120
  end
122
121
 
123
122
  def visit_STAR node
124
- "(.+)"
123
+ re = @matchers[node.left.to_sym] || '.+'
124
+ "(#{re})"
125
125
  end
126
126
  end
127
127
 
@@ -172,11 +172,11 @@ module Journey
172
172
  to_regexp.source
173
173
  end
174
174
 
175
- private
176
175
  def to_regexp
177
176
  @re ||= regexp_visitor.new(@separators, @requirements).accept spec
178
177
  end
179
178
 
179
+ private
180
180
  def regexp_visitor
181
181
  @anchored ? AnchoredRegexp : UnanchoredRegexp
182
182
  end
data/lib/journey/route.rb CHANGED
@@ -5,7 +5,7 @@ module Journey
5
5
  attr_reader :constraints
6
6
  alias :conditions :constraints
7
7
 
8
- attr_accessor :precidence
8
+ attr_accessor :precedence
9
9
 
10
10
  ##
11
11
  # +path+ is a path constraint.
@@ -25,7 +25,7 @@ module Journey
25
25
  @required_parts = nil
26
26
  @parts = nil
27
27
  @decorated_ast = nil
28
- @precidence = 0
28
+ @precedence = 0
29
29
  end
30
30
 
31
31
  def ast
@@ -17,7 +17,7 @@ module Journey
17
17
  class RoutingError < ::StandardError
18
18
  end
19
19
 
20
- VERSION = '1.0.0.rc2'
20
+ VERSION = '1.0.0.rc3'
21
21
 
22
22
  class NullReq # :nodoc:
23
23
  attr_reader :env
@@ -122,7 +122,7 @@ module Journey
122
122
  r.path.match(env['PATH_INFO'])
123
123
  }
124
124
 
125
- routes.sort_by(&:precidence).find_all { |r|
125
+ routes.sort_by(&:precedence).find_all { |r|
126
126
  r.constraints.all? { |k,v| v === req.send(k) } &&
127
127
  r.verb === env['REQUEST_METHOD']
128
128
  }.reject { |r| addr && !(r.ip === addr) }.map { |r|
@@ -58,7 +58,7 @@ module Journey
58
58
  def add_route app, path, conditions, defaults, name = nil
59
59
  route = Route.new(name, app, path, conditions, defaults)
60
60
 
61
- route.precidence = routes.length
61
+ route.precedence = routes.length
62
62
  routes << route
63
63
  named_routes[name] = route if name && !named_routes[name]
64
64
  clear_cache!
@@ -5,16 +5,16 @@ module Journey
5
5
  class TestPattern < MiniTest::Unit::TestCase
6
6
  x = /.+/
7
7
  {
8
- '/:controller(/:action)' => %r{\A/(#{x}?)(?:/([^/.?]+))?\Z},
9
- '/:controller/foo' => %r{\A/(#{x}?)/foo\Z},
10
- '/:controller/:action' => %r{\A/(#{x}?)/([^/.?]+)\Z},
11
- '/:controller' => %r{\A/(#{x}?)\Z},
12
- '/:controller(/:action(/:id))' => %r{\A/(#{x}?)(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z},
13
- '/:controller/:action.xml' => %r{\A/(#{x}?)/([^/.?]+)\.xml\Z},
14
- '/:controller.:format' => %r{\A/(#{x}?)\.([^/.?]+)\Z},
15
- '/:controller(.:format)' => %r{\A/(#{x}?)(?:\.([^/.?]+))?\Z},
16
- '/:controller/*foo' => %r{\A/(#{x}?)/(.+)\Z},
17
- '/:controller/*foo/bar' => %r{\A/(#{x}?)/(.+)/bar\Z},
8
+ '/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?\Z},
9
+ '/:controller/foo' => %r{\A/(#{x})/foo\Z},
10
+ '/:controller/:action' => %r{\A/(#{x})/([^/.?]+)\Z},
11
+ '/:controller' => %r{\A/(#{x})\Z},
12
+ '/:controller(/:action(/:id))' => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z},
13
+ '/:controller/:action.xml' => %r{\A/(#{x})/([^/.?]+)\.xml\Z},
14
+ '/:controller.:format' => %r{\A/(#{x})\.([^/.?]+)\Z},
15
+ '/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?\Z},
16
+ '/:controller/*foo' => %r{\A/(#{x})/(.+)\Z},
17
+ '/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar\Z},
18
18
  }.each do |path, expected|
19
19
  define_method(:"test_to_regexp_#{path}") do
20
20
  strexp = Router::Strexp.new(
@@ -23,21 +23,21 @@ module Journey
23
23
  ["/", ".", "?"]
24
24
  )
25
25
  path = Pattern.new strexp
26
- assert_equal(expected, path.send(:to_regexp))
26
+ assert_equal(expected, path.to_regexp)
27
27
  end
28
28
  end
29
29
 
30
30
  {
31
- '/:controller(/:action)' => %r{\A/(#{x}?)(?:/([^/.?]+))?},
32
- '/:controller/foo' => %r{\A/(#{x}?)/foo},
33
- '/:controller/:action' => %r{\A/(#{x}?)/([^/.?]+)},
34
- '/:controller' => %r{\A/(#{x}?)},
35
- '/:controller(/:action(/:id))' => %r{\A/(#{x}?)(?:/([^/.?]+)(?:/([^/.?]+))?)?},
36
- '/:controller/:action.xml' => %r{\A/(#{x}?)/([^/.?]+)\.xml},
37
- '/:controller.:format' => %r{\A/(#{x}?)\.([^/.?]+)},
38
- '/:controller(.:format)' => %r{\A/(#{x}?)(?:\.([^/.?]+))?},
39
- '/:controller/*foo' => %r{\A/(#{x}?)/(.+)},
40
- '/:controller/*foo/bar' => %r{\A/(#{x}?)/(.+)/bar},
31
+ '/:controller(/:action)' => %r{\A/(#{x})(?:/([^/.?]+))?},
32
+ '/:controller/foo' => %r{\A/(#{x})/foo},
33
+ '/:controller/:action' => %r{\A/(#{x})/([^/.?]+)},
34
+ '/:controller' => %r{\A/(#{x})},
35
+ '/:controller(/:action(/:id))' => %r{\A/(#{x})(?:/([^/.?]+)(?:/([^/.?]+))?)?},
36
+ '/:controller/:action.xml' => %r{\A/(#{x})/([^/.?]+)\.xml},
37
+ '/:controller.:format' => %r{\A/(#{x})\.([^/.?]+)},
38
+ '/:controller(.:format)' => %r{\A/(#{x})(?:\.([^/.?]+))?},
39
+ '/:controller/*foo' => %r{\A/(#{x})/(.+)},
40
+ '/:controller/*foo/bar' => %r{\A/(#{x})/(.+)/bar},
41
41
  }.each do |path, expected|
42
42
  define_method(:"test_to_non_anchored_regexp_#{path}") do
43
43
  strexp = Router::Strexp.new(
@@ -47,7 +47,7 @@ module Journey
47
47
  false
48
48
  )
49
49
  path = Pattern.new strexp
50
- assert_equal(expected, path.send(:to_regexp))
50
+ assert_equal(expected, path.to_regexp)
51
51
  end
52
52
  end
53
53
 
@@ -101,6 +101,17 @@ module Journey
101
101
  end
102
102
  end
103
103
 
104
+ def test_to_regexp_match_non_optional
105
+ strexp = Router::Strexp.new(
106
+ '/:name',
107
+ { :name => /\d+/ },
108
+ ["/", ".", "?"]
109
+ )
110
+ path = Pattern.new strexp
111
+ assert_match('/123', path)
112
+ refute_match('/', path)
113
+ end
114
+
104
115
  def test_to_regexp_with_group
105
116
  strexp = Router::Strexp.new(
106
117
  '/page/:name',
@@ -157,6 +168,17 @@ module Journey
157
168
  assert_equal %w{ tender 10 }, match.captures
158
169
  end
159
170
 
171
+ def test_star_with_custom_re
172
+ z = /\d+/
173
+ strexp = Router::Strexp.new(
174
+ '/page/*foo',
175
+ { :foo => z },
176
+ ["/", ".", "?"]
177
+ )
178
+ path = Pattern.new strexp
179
+ assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp)
180
+ end
181
+
160
182
  def test_insensitive_regexp_with_group
161
183
  strexp = Router::Strexp.new(
162
184
  '/page/:name/aaron',
@@ -180,7 +202,7 @@ module Journey
180
202
  def test_to_regexp_defaults
181
203
  path = Pattern.new '/:controller(/:action(/:id))'
182
204
  expected = %r{\A/([^/.?]+)(?:/([^/.?]+)(?:/([^/.?]+))?)?\Z}
183
- assert_equal expected, path.send(:to_regexp)
205
+ assert_equal expected, path.to_regexp
184
206
  end
185
207
 
186
208
  def test_failed_match
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: journey
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc2
4
+ version: 1.0.0.rc3
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-21 00:00:00.000000000 Z
12
+ date: 2011-12-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &70190462428740 !ruby/object:Gem::Requirement
16
+ requirement: &70284201057560 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.9'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70190462428740
24
+ version_requirements: *70284201057560
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: racc
27
- requirement: &70190462428320 !ruby/object:Gem::Requirement
27
+ requirement: &70284201057120 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 1.4.6
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70190462428320
35
+ version_requirements: *70284201057120
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rdoc
38
- requirement: &70190462427900 !ruby/object:Gem::Requirement
38
+ requirement: &70284201056700 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '3.11'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70190462427900
46
+ version_requirements: *70284201056700
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: json
49
- requirement: &70190462427540 !ruby/object:Gem::Requirement
49
+ requirement: &70284201056340 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70190462427540
57
+ version_requirements: *70284201056340
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: hoe
60
- requirement: &70190462427080 !ruby/object:Gem::Requirement
60
+ requirement: &70284201055880 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '2.12'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70190462427080
68
+ version_requirements: *70284201055880
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rdoc
71
- requirement: &70190462693860 !ruby/object:Gem::Requirement
71
+ requirement: &70284201323800 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '3.10'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70190462693860
79
+ version_requirements: *70284201323800
80
80
  description: Journey is a router. It routes requests.
81
81
  email:
82
82
  - aaron@tenderlovemaking.com