cuba 3.8.0 → 3.8.1
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.
- checksums.yaml +4 -4
- data/README.md +42 -1
- data/cuba.gemspec +1 -1
- data/lib/cuba.rb +0 -1
- data/test/composition.rb +36 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6428d24a19fc99881ffad1b18f7757fe6c3656d8
|
4
|
+
data.tar.gz: 22adf9cf4289ff9976cb364a3c4b9795e7225015
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27074004e24756499709bd7c6272e54e2d4c60e6ced2831f893872a514a8ef85d2d91f6c5a4eb70f39565f5059be84e407ffb45a82e66244e3b9521c3c219ae8
|
7
|
+
data.tar.gz: c4e893414f0cfa688a583bccf516e646514ae635cb37ee79a74f3b2bbd48eb886623a8447eab39f2840057bb5706676d9c302ca896f98b6d50c844df344b670b
|
data/README.md
CHANGED
@@ -360,7 +360,7 @@ Cuba.define do
|
|
360
360
|
csrf.reset!
|
361
361
|
|
362
362
|
res.status = 403
|
363
|
-
res.write("
|
363
|
+
res.write("Forbidden")
|
364
364
|
|
365
365
|
halt(res.finish)
|
366
366
|
end
|
@@ -514,6 +514,47 @@ Cuba.define do
|
|
514
514
|
end
|
515
515
|
```
|
516
516
|
|
517
|
+
## Embedding routes from other modules
|
518
|
+
|
519
|
+
While the `run` command allows you to handle over the control to a
|
520
|
+
sub app, sometimes you may want to just embed routes defined in
|
521
|
+
another module. There's no built-in method to do it, but if you are
|
522
|
+
willing to experiment you can try the following.
|
523
|
+
|
524
|
+
Let's say you have defined routes in modules `A` and `B`, and you
|
525
|
+
want to mount those routes in your application.
|
526
|
+
|
527
|
+
First, you will have to extend Cuba with this code:
|
528
|
+
|
529
|
+
```ruby
|
530
|
+
class Cuba
|
531
|
+
def mount(app)
|
532
|
+
result = app.call(req.env)
|
533
|
+
halt result if result[0] != 404
|
534
|
+
end
|
535
|
+
end
|
536
|
+
```
|
537
|
+
|
538
|
+
It doesn't matter where you define it as long as Cuba has already
|
539
|
+
been required. For instance, you could extract that to a plugin and
|
540
|
+
it would work just fine.
|
541
|
+
|
542
|
+
Then, in your application, you can use it like this:
|
543
|
+
|
544
|
+
```ruby
|
545
|
+
Cuba.define do
|
546
|
+
on default do
|
547
|
+
mount A
|
548
|
+
mount B
|
549
|
+
end
|
550
|
+
end
|
551
|
+
```
|
552
|
+
|
553
|
+
It should halt the request only if the resulting status from calling
|
554
|
+
the mounted app is not 404. If you run into some unexpected behavior,
|
555
|
+
let me know by creating an issue and we'll look at how to workaround
|
556
|
+
any difficulties.
|
557
|
+
|
517
558
|
Testing
|
518
559
|
-------
|
519
560
|
|
data/cuba.gemspec
CHANGED
data/lib/cuba.rb
CHANGED
data/test/composition.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
require File.expand_path("helper", File.dirname(__FILE__))
|
2
2
|
|
3
3
|
test "composing on top of a PATH" do
|
4
|
-
Services = Cuba.new
|
4
|
+
Services = Cuba.new do
|
5
5
|
on "services/:id" do |id|
|
6
6
|
res.write "View #{id}"
|
7
7
|
end
|
8
|
-
|
8
|
+
end
|
9
9
|
|
10
10
|
Cuba.define do
|
11
11
|
on "provider" do
|
@@ -67,3 +67,37 @@ test "redefining not_found" do
|
|
67
67
|
assert_response resp, ["Error 404"]
|
68
68
|
assert_equal status, 404
|
69
69
|
end
|
70
|
+
|
71
|
+
test "multi mount" do
|
72
|
+
A = Cuba.new do
|
73
|
+
on "a" do
|
74
|
+
res.write "View a"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
B = Cuba.new do
|
79
|
+
on "b" do
|
80
|
+
res.write "View b"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
class Cuba
|
85
|
+
def mount(app)
|
86
|
+
result = app.call(req.env)
|
87
|
+
halt result if result[0] != 404
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
Cuba.define do
|
92
|
+
on default do
|
93
|
+
mount A
|
94
|
+
mount B
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/b" }
|
99
|
+
|
100
|
+
_, _, resp = Cuba.call(env)
|
101
|
+
|
102
|
+
assert_response resp, ["View b"]
|
103
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.8.
|
4
|
+
version: 3.8.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michel Martens
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -153,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
153
|
version: '0'
|
154
154
|
requirements: []
|
155
155
|
rubyforge_project:
|
156
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.6.11
|
157
157
|
signing_key:
|
158
158
|
specification_version: 4
|
159
159
|
summary: Microframework for web applications.
|