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.
- data/lib/http_router/interface/sinatra.rb +8 -8
- data/lib/http_router/version.rb +1 -1
- data/lib/http_router.rb +1 -1
- data/spec/sinatra/recognize_spec.rb +27 -0
- metadata +3 -3
@@ -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
|
-
|
68
|
-
|
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
|
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
|
|
data/lib/http_router/version.rb
CHANGED
data/lib/http_router.rb
CHANGED
@@ -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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 4
|
10
|
+
version: 0.3.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Hull
|