http_router 0.3.3 → 0.3.4

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.
@@ -63,21 +63,21 @@ class HttpRouter
63
63
 
64
64
  define_method "#{verb} #{path}", &block
65
65
  unbound_method = instance_method("#{verb} #{path}")
66
- block =
67
- if block.arity != 0
68
- proc { unbound_method.bind(self).call(*@block_params) }
69
- else
70
- proc { unbound_method.bind(self).call }
71
- end
66
+ block = block.arity.zero? ?
67
+ proc { unbound_method.bind(self).call } :
68
+ proc { unbound_method.bind(self).call(*@block_params) }
72
69
 
73
70
  invoke_hook(:route_added, verb, path, block)
74
71
 
75
72
  route = router.add(path)
73
+
74
+ route.matching(options[:matching]) if options.key?(:matching)
75
+
76
76
  route.request_method(verb)
77
- route.host(options.delete(:host)) if options.key?(:host)
77
+ route.host(options[:host]) if options.key?(:host)
78
78
 
79
- route.to(block)
80
79
  route.name(name) if name
80
+ route.to(block)
81
81
  route
82
82
  end
83
83
 
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  class HttpRouter #:nodoc
3
- VERSION = '0.3.3'
3
+ VERSION = '0.3.4'
4
4
  end
data/lib/http_router.rb CHANGED
@@ -229,7 +229,7 @@ class HttpRouter
229
229
  Glob.new(self, *args)
230
230
  end
231
231
 
232
- # Returns a new glob
232
+ # Returns a new route
233
233
  def route(*args)
234
234
  Route.new(self, *args)
235
235
  end
@@ -118,6 +118,33 @@ describe "HttpRouter (for Sinatra) route recognition" do
118
118
  end
119
119
  end
120
120
 
121
+ describe "matching by regexp" do
122
+ before :each do
123
+ @app.get('/numbers/:digits', :matching => { :digits => /\d+/ }) { params[:digits] }
124
+ end
125
+
126
+ describe "when regexp is matched" do
127
+ before :each do
128
+ @response = @app.call_with_mock_request('/numbers/2010')
129
+ end
130
+
131
+ it "should map successfully" do
132
+ @response.status.should == 200
133
+ @response.body.should == "2010"
134
+ end
135
+ end
136
+
137
+ describe "when regexp is not matched" do
138
+ before :each do
139
+ @response = @app.call_with_mock_request('/numbers/boobs')
140
+ end
141
+
142
+ it "should not map" do
143
+ @response.status.should == 404
144
+ end
145
+ end
146
+ end
147
+
121
148
  describe "not found" do
122
149
 
123
150
  it "should correctly generate a not found page without images" do
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: 21
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 3
10
- version: 0.3.3
9
+ - 4
10
+ version: 0.3.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Hull