http_router 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/http_router.gemspec +1 -1
- data/lib/http_router/route.rb +5 -0
- data/lib/http_router/version.rb +1 -2
- data/spec/recognize_spec.rb +9 -0
- metadata +4 -4
data/http_router.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = HttpRouter::VERSION
|
8
8
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
9
9
|
s.authors = ["Joshua Hull"]
|
10
|
-
s.date =
|
10
|
+
s.date = '2010-07-31'
|
11
11
|
s.summary = "A kick-ass HTTP router for use in Rack & Sinatra"
|
12
12
|
s.description = "This library allows you to recognize and build URLs in a Rack application. As well it contains an interface for use within Sinatra."
|
13
13
|
s.email = %q{joshbuddy@gmail.com}
|
data/lib/http_router/route.rb
CHANGED
@@ -164,6 +164,11 @@ class HttpRouter
|
|
164
164
|
self
|
165
165
|
end
|
166
166
|
|
167
|
+
# Convenient regexp matching on an entire path. Returns +self+
|
168
|
+
def match_path(matcher)
|
169
|
+
arbitrary{|env| match = matcher.match(env.path_info); !match.nil? and match.begin(0) == 0 and match[0].size == env.path_info.size}
|
170
|
+
end
|
171
|
+
|
167
172
|
# Adds an arbitrary proc matcher to a Route. Receives either a block, or a proc. The proc will receive a Rack::Request object and must return true for the Route to be matched. Returns +self+.
|
168
173
|
def arbitrary(proc = nil, &block)
|
169
174
|
@arbitrary << (proc || block)
|
data/lib/http_router/version.rb
CHANGED
data/spec/recognize_spec.rb
CHANGED
@@ -209,6 +209,15 @@ describe "HttpRouter#recognize" do
|
|
209
209
|
response.params_as_hash[:variable].should == 'value'
|
210
210
|
end
|
211
211
|
|
212
|
+
it "should recognize using match_path" do
|
213
|
+
route = @router.add('/:test').match_path(%r{/(test123|\d+)}).to(:test)
|
214
|
+
@router.recognize(Rack::MockRequest.env_for('/test123')).params_as_hash[:test].should == 'test123'
|
215
|
+
@router.recognize(Rack::MockRequest.env_for('/123')).params_as_hash[:test].should == '123'
|
216
|
+
@router.recognize(Rack::MockRequest.env_for('/test321')).should be_nil
|
217
|
+
@router.recognize(Rack::MockRequest.env_for('/test123andmore')).should be_nil
|
218
|
+
@router.recognize(Rack::MockRequest.env_for('/lesstest123')).should be_nil
|
219
|
+
end
|
220
|
+
|
212
221
|
it "should recognize '/test.:format'" do
|
213
222
|
route = @router.add('/test.:format').to(:test)
|
214
223
|
response = @router.recognize(Rack::MockRequest.env_for('/test.html'))
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 6
|
10
|
+
version: 0.3.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Hull
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-31 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|