rack-multiplexer 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1693a2a3b7c5e01ff4504b1050be22e70d56a476
4
- data.tar.gz: be765bf4e45551f7888e8d445fe9046ea6209d94
3
+ metadata.gz: 56192c72de737b0bf6d3f134b3de57774be7613e
4
+ data.tar.gz: d27bf614ecef2456e7f2e3970e1d7b3a7190efde
5
5
  SHA512:
6
- metadata.gz: e74c42adeebd12b164e473584ccf15b3745e4706ca21bf0c2bcbadf836474d76b7ebbaa1ba483d67ca6952a6cd15ece7d0da101e5d79f14d417baadd0485a68b
7
- data.tar.gz: 0c0e978e9bb4aff842e0353e044eafae25df42328deacccace09534b7eb6d3d7131fbf83ce0e78dd98841cf95da6cc329a32f4033dc97637f0cce4c0606951f2
6
+ metadata.gz: accd2f8899fb5d0cd0921c727980eeb6f4f2eca86f9865c830b613f08848bb9a4ca0afe268243a43ff5083cad64e17c5e89700e1bb710ed58432361e40e5cb9a
7
+ data.tar.gz: f382488b74aaba47a00b802ed3ef4c072f6424b23ae551b127cf2f357c07efd231a825463883e7eee741e0ebde8b9486a5fee0f9c2c2f3366c97e0164d2b0d43
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Rack::Multiplexer
2
2
  Provides a simple router & dispatcher for Rack applications as a Rack application.
3
- The routing algorithm has only O(1) time complexity because all routes are compiled into one Regexp.
3
+ The routing algorithm has only O(1) time complexity in Ruby level because all routes are compiled into one Regexp.
4
4
 
5
5
  ## Installation
6
6
  ```
@@ -128,7 +128,7 @@ module Rack
128
128
  keys << key
129
129
  end
130
130
  end
131
- return Regexp.new(segments.join(?/)), keys
131
+ return Regexp.new(segments.any? ? segments.join(?/) : ?/), keys
132
132
  end
133
133
  end
134
134
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  class Multiplexer
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  end
5
5
  end
data/scripts/benchmark.rb CHANGED
@@ -1,28 +1,25 @@
1
- # Benchmark script for comparison of the routing algorithm between v0.0.2 and v0.0.3.
2
- # In my laptop environment, v0.0.3 is 17x faster than 0.0.2 with 676 routes & 100,000 tries.
3
-
4
1
  $LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
5
2
  require "rack/multiplexer"
6
3
  require "benchmark"
7
4
 
8
- multiplexer = Rack::Multiplexer.new
9
- (?a..?z).each do |head|
10
- (?a..?z).each do |tail|
11
- multiplexer.get("/#{head}{tail}") do
12
- [200, {}, ["OK"]]
13
- end
14
- end
15
- end
16
-
5
+ characters = (?a..?z).to_a
17
6
  env = {
18
7
  "PATH_INFO" => "/mm",
19
8
  "REQUEST_METHOD" => "GET",
20
9
  }
21
-
22
10
  n = 100_000
23
- puts Benchmark::CAPTION
24
- puts Benchmark.measure {
11
+
12
+ 26.times do |i|
13
+ multiplexer = Rack::Multiplexer.new
14
+ characters[0, i + 1].each do |character|
15
+ multiplexer.get("/#{character}") do
16
+ [200, {}, ["OK"]]
17
+ end
18
+ end
19
+
20
+ before = Time.now
25
21
  n.times do
26
22
  multiplexer.call(env)
27
23
  end
28
- }
24
+ puts Time.now - before
25
+ end
@@ -120,5 +120,13 @@ describe Rack::Multiplexer do
120
120
  multiplexer.call(env.merge("REQUEST_METHOD" => "GET", "PATH_INFO" => "/abc"))[0].should == 404
121
121
  end
122
122
  end
123
+
124
+ context "with root path" do
125
+ it "delegates to registered application" do
126
+ multiplexer = described_class.new
127
+ multiplexer.get("/", application)
128
+ multiplexer.call(env.merge("REQUEST_METHOD" => "GET", "PATH_INFO" => "/"))[0].should == 200
129
+ end
130
+ end
123
131
  end
124
132
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-multiplexer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-27 00:00:00.000000000 Z
11
+ date: 2014-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -140,3 +140,4 @@ summary: Provides a simple router & dispatcher for Rack.
140
140
  test_files:
141
141
  - spec/rack/multiplexer_spec.rb
142
142
  - spec/spec_helper.rb
143
+ has_rdoc: