http_router 0.7.3 → 0.7.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -71,7 +71,7 @@ class HttpRouter
71
71
  end
72
72
 
73
73
  def set_pass_on_response(&blk)
74
- extend(Module.new{define_method(:pass_on_response, &blk)})
74
+ extend(Module.new { define_method(:pass_on_response, &blk) })
75
75
  end
76
76
 
77
77
  # Adds a path that only responds to the request method +GET+.
@@ -120,10 +120,10 @@ class HttpRouter
120
120
  else
121
121
  request = Request.new(rack_request.path_info, rack_request, perform_call)
122
122
  response = catch(:success) { @root[request] }
123
- if response.nil?
124
- no_response(env, perform_call)
125
- elsif response
123
+ if response
126
124
  response
125
+ elsif response.nil?
126
+ no_response(env, perform_call)
127
127
  elsif perform_call
128
128
  @default_app.call(env)
129
129
  else
@@ -134,10 +134,8 @@ class HttpRouter
134
134
 
135
135
  # Resets the router to a clean state.
136
136
  def reset!
137
- @root = Node.new(self)
137
+ @routes, @named_routes, @root = [], {}, Node.new(self)
138
138
  @default_app = Proc.new{ |env| ::Rack::Response.new("Your request couldn't be found", 404).finish }
139
- @routes = []
140
- @named_routes = {}
141
139
  end
142
140
 
143
141
  # Assigns the default application.
@@ -82,6 +82,7 @@ class HttpRouter
82
82
  end
83
83
 
84
84
  def matching(matchers)
85
+ matchers = Hash[*matchers] if matchers.is_a?(Array)
85
86
  @opts.merge!(matchers)
86
87
  self
87
88
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.7.3'
3
+ VERSION = '0.7.4'
4
4
  end
@@ -76,6 +76,11 @@ class TestVariable < MiniTest::Unit::TestCase
76
76
  assert_route r, '/foo', {:test => 'foo'}
77
77
  end
78
78
 
79
+ def test_var_with_optional_format_and_regex
80
+ r = router { add('/:test(.:format)', :format => /[^\.]+/) }
81
+ assert_route r, '/asd@asd.com.json', {:test => 'asd@asd.com', :format => 'json'}
82
+ end
83
+
79
84
  def test_glob
80
85
  assert_route '/test/*variable', 'test/one/two/three', {:variable => ['one', 'two', 'three']}
81
86
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_router
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 7
9
- - 3
10
- version: 0.7.3
9
+ - 4
10
+ version: 0.7.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull