rack-multiplexer 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +18 -0
- data/lib/rack/multiplexer.rb +10 -10
- data/lib/rack/multiplexer/version.rb +1 -1
- data/spec/rack/multiplexer_spec.rb +9 -1
- metadata +1 -2
- data/config.ru +0 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6995959f7734df487ab98f351f5714867fa8159
|
4
|
+
data.tar.gz: 5da14e65a19d2f3e8df203bcb05c70920b00ccdf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a8f890c52663e8d5b908d0f47bc85392e2d3429faadbccfa14cd0f2b41ae7d4badc7585e20b915e0152b8bcaab907d6258020190f385ee758917c8a1458f297
|
7
|
+
data.tar.gz: b3f3a4fac56c8dab21869a8a5e35417745c9f795cf85df192eb1ff8a6b6fa2b5d08cea449856bb08344a2665dff4e84f0626c011eb755db63b36b2872a3d32a3
|
data/README.md
CHANGED
@@ -23,3 +23,21 @@ multiplexer.get("/f/:g", ->(env) { [200, {}, [env["rack.request.query_hash"]["g"
|
|
23
23
|
|
24
24
|
run multiplexer
|
25
25
|
```
|
26
|
+
|
27
|
+
## DSL
|
28
|
+
The block is with you, always.
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
# config.ru
|
32
|
+
require "rack-multiplexer"
|
33
|
+
|
34
|
+
run Rack::Multiplexer.new {
|
35
|
+
get "/a" do
|
36
|
+
[200, {}, ["a"]]
|
37
|
+
end
|
38
|
+
|
39
|
+
get "/b/:c" do
|
40
|
+
[200, {}, ["d"]]
|
41
|
+
end
|
42
|
+
}
|
43
|
+
```
|
data/lib/rack/multiplexer.rb
CHANGED
@@ -28,24 +28,24 @@ module Rack
|
|
28
28
|
).call(env)
|
29
29
|
end
|
30
30
|
|
31
|
-
def get(pattern, application)
|
32
|
-
append("GET", pattern, application)
|
31
|
+
def get(pattern, application = nil, &block)
|
32
|
+
append("GET", pattern, application || block)
|
33
33
|
end
|
34
34
|
|
35
|
-
def post(pattern, application)
|
36
|
-
append("POST", pattern, application)
|
35
|
+
def post(pattern, application = nil, &block)
|
36
|
+
append("POST", pattern, application || block)
|
37
37
|
end
|
38
38
|
|
39
|
-
def put(pattern, application)
|
40
|
-
append("PUT", pattern, application)
|
39
|
+
def put(pattern, application = nil, &block)
|
40
|
+
append("PUT", pattern, application || block)
|
41
41
|
end
|
42
42
|
|
43
|
-
def delete(pattern, application)
|
44
|
-
append("DELETE", pattern, application)
|
43
|
+
def delete(pattern, application = nil, &block)
|
44
|
+
append("DELETE", pattern, application || block)
|
45
45
|
end
|
46
46
|
|
47
|
-
def any(pattern, application)
|
48
|
-
append("ANY", pattern, application)
|
47
|
+
def any(pattern, application, &block)
|
48
|
+
append("ANY", pattern, application || block)
|
49
49
|
end
|
50
50
|
|
51
51
|
def append(method, pattern, application)
|
@@ -28,7 +28,7 @@ describe Rack::Multiplexer do
|
|
28
28
|
multiplexer = described_class.new
|
29
29
|
multiplexer.call(env.merge("REQUEST_METHOD" => "GET", "PATH_INFO" => "/a")).should == [
|
30
30
|
404,
|
31
|
-
{ "Content-Type" => "text/plain", "Content-Length" => 0 },
|
31
|
+
{ "Content-Type" => "text/plain", "Content-Length" => "0" },
|
32
32
|
[""],
|
33
33
|
]
|
34
34
|
end
|
@@ -92,6 +92,14 @@ describe Rack::Multiplexer do
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
context "with block routing" do
|
96
|
+
it "delegates to given block as rack application" do
|
97
|
+
multiplexer = described_class.new
|
98
|
+
multiplexer.get("/a") {|env| [200, {}, ["a"]] }
|
99
|
+
multiplexer.call(env.merge("REQUEST_METHOD" => "GET", "PATH_INFO" => "/a"))[0].should == 200
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
95
103
|
context "with any routing" do
|
96
104
|
it "matches any method" do
|
97
105
|
multiplexer = described_class.new
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-multiplexer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -106,7 +106,6 @@ files:
|
|
106
106
|
- LICENSE.txt
|
107
107
|
- README.md
|
108
108
|
- Rakefile
|
109
|
-
- config.ru
|
110
109
|
- lib/rack-multiplexer.rb
|
111
110
|
- lib/rack/multiplexer.rb
|
112
111
|
- lib/rack/multiplexer/version.rb
|
data/config.ru
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require "rack-multiplexer"
|
2
|
-
|
3
|
-
multiplexer = Rack::Multiplexer.new
|
4
|
-
multiplexer.get("/a", ->(env) { [200, {}, ["a"]] })
|
5
|
-
multiplexer.get("/b", ->(env) { [200, {}, ["b"]] })
|
6
|
-
multiplexer.post("/c", ->(env) { [200, {}, ["c"]] })
|
7
|
-
multiplexer.put("/d", ->(env) { [200, {}, ["c"]] })
|
8
|
-
multiplexer.delete("/e", ->(env) { [200, {}, ["c"]] })
|
9
|
-
multiplexer.get("/f/:g", ->(env) { [200, {}, [env["rack.request.query_hash"]["g"]]] })
|
10
|
-
|
11
|
-
run multiplexer
|