cuba 3.8.0 → 3.8.1

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: c41182a06c40d94e076e5cd07b77a1b6b09c2129
4
- data.tar.gz: 33cedd76ce5cea5a70a0db7ec33b405e5b0153ba
3
+ metadata.gz: 6428d24a19fc99881ffad1b18f7757fe6c3656d8
4
+ data.tar.gz: 22adf9cf4289ff9976cb364a3c4b9795e7225015
5
5
  SHA512:
6
- metadata.gz: 7093091a3b5e98389553d608bf4e7cedb9818141d0e09fbd6132c27e5783f04b97e9d151ba7234e5dd81a41d28d9e9dd80547e4d878bf4a098a6ebdfd886740a
7
- data.tar.gz: 829c737f9dc612a532a0650a8a84a3a46671e153f74dfb10faead95de4e378afc6778c2ac8b3371d1e72a6c250f392f0f10dc5e30aa945c04d0083afdbf1abc7
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("Not authorized")
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
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cuba"
3
- s.version = "3.8.0"
3
+ s.version = "3.8.1"
4
4
  s.summary = "Microframework for web applications."
5
5
  s.description = "Cuba is a microframework for web applications."
6
6
  s.authors = ["Michel Martens"]
@@ -1,5 +1,4 @@
1
1
  require "rack"
2
- require "time"
3
2
 
4
3
  class Cuba
5
4
  SLASH = "/".freeze
@@ -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.0
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: 2016-07-01 00:00:00.000000000 Z
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.4.5.1
156
+ rubygems_version: 2.6.11
157
157
  signing_key:
158
158
  specification_version: 4
159
159
  summary: Microframework for web applications.