cuba 0.2.0 → 0.3.0

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.
data/README.markdown CHANGED
@@ -66,7 +66,7 @@ check the documentation for [Cutest](http://github.com/djanowski/cutest) and
66
66
  Installation
67
67
  ------------
68
68
 
69
- $ sudo gem install cuba
69
+ $ gem install cuba
70
70
 
71
71
  License
72
72
  -------
data/cuba.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "cuba"
3
- s.version = "0.2.0"
3
+ s.version = "0.3.0"
4
4
  s.summary = "Rum based microframework for web applications."
5
5
  s.description = "Cuba is a light wrapper for Rum, a microframework for Rack applications."
6
6
  s.authors = ["Michel Martens"]
data/lib/cuba.rb CHANGED
@@ -2,19 +2,28 @@ require "cuba/version"
2
2
  require "cuba/ron"
3
3
 
4
4
  module Cuba
5
+ def self.reset!
6
+ @app = nil
7
+ @prototype = nil
8
+ end
9
+
5
10
  def self.app
6
11
  @app ||= Rack::Builder.new
7
12
  end
8
13
 
9
- def self.use(middleware)
10
- app.use(middleware)
14
+ def self.use(middleware, *args, &block)
15
+ app.use(middleware, *args, &block)
11
16
  end
12
17
 
13
18
  def self.define(&block)
14
19
  app.run Cuba::Ron.new(&block)
15
20
  end
16
21
 
22
+ def self.prototype
23
+ @prototype ||= app.to_app
24
+ end
25
+
17
26
  def self.call(env)
18
- app.call(env)
27
+ prototype.call(env)
19
28
  end
20
- end
29
+ end
data/lib/cuba/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Cuba
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/test/integration.rb CHANGED
@@ -1,4 +1,95 @@
1
+ $:.unshift(File.expand_path("../lib", File.dirname(__FILE__)))
2
+ require "cuba"
3
+
4
+ prepare { Cuba.reset! }
5
+
6
+ test "resetting" do
7
+ old = Cuba.app
8
+ assert old.object_id == Cuba.app.object_id
9
+
10
+ Cuba.reset!
11
+ assert old.object_id != Cuba.app.object_id
12
+ end
13
+
14
+ class Middle
15
+ def initialize(app, first, second, &block)
16
+ @app, @first, @second, @block = app, first, second, block
17
+ end
18
+
19
+ def call(env)
20
+ env["m.first"] = @first
21
+ env["m.second"] = @second
22
+ env["m.block"] = @block.call
23
+
24
+ @app.call(env)
25
+ end
26
+ end
27
+
28
+ test "use passes in the arguments and block" do
29
+ Cuba.use Middle, "First", "Second" do
30
+ "this is the block"
31
+ end
32
+
33
+ Cuba.define do
34
+ on get do
35
+ on path("hello") do
36
+ "Default"
37
+ end
38
+ end
39
+ end
40
+
41
+ env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/hello",
42
+ "SCRIPT_NAME" => "/" }
43
+
44
+ Cuba.call(env)
45
+
46
+ assert "First" == env["m.first"]
47
+ assert "Second" == env["m.second"]
48
+ assert "this is the block" == env["m.block"]
49
+ end
50
+
51
+ test "reset and use" do
52
+ Cuba.use Middle, "First", "Second" do
53
+ "this is the block"
54
+ end
55
+
56
+ Cuba.define do
57
+ on get do
58
+ on path("hello") do
59
+ res.write "Default"
60
+ end
61
+ end
62
+ end
63
+
64
+ Cuba.reset!
65
+
66
+ Cuba.use Middle, "1", "2" do
67
+ "3"
68
+ end
69
+
70
+ Cuba.define do
71
+ on get do
72
+ on path("hello") do
73
+ res.write "2nd Default"
74
+ end
75
+ end
76
+ end
77
+
78
+ env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/hello",
79
+ "SCRIPT_NAME" => "/" }
80
+
81
+ status, headers, resp = Cuba.call(env)
82
+
83
+ assert 200 == status
84
+ assert "text/html" == headers["Content-Type"]
85
+ assert ["2nd Default"] == resp.body
86
+
87
+ assert "1" == env["m.first"]
88
+ assert "2" == env["m.second"]
89
+ assert "3" == env["m.block"]
90
+ end
91
+
1
92
  test "examples" do
2
93
  `cd example && rake -I../lib`
3
94
  assert $?.exitstatus == 0
4
- end
95
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 0.2.0
9
+ version: 0.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Michel Martens
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-25 00:00:00 -03:00
17
+ date: 2010-10-09 00:00:00 -03:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency