cuba 2.0.0.rc3 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/cuba.gemspec +4 -4
- data/lib/cuba/ron.rb +6 -6
- data/lib/cuba/version.rb +2 -2
- data/test/accept.rb +18 -0
- data/test/captures.rb +0 -17
- data/test/param.rb +44 -0
- metadata +8 -7
data/cuba.gemspec
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "cuba"
|
3
|
-
s.version = "2.0.0
|
4
|
-
s.summary = "
|
5
|
-
s.description = "Cuba is a
|
3
|
+
s.version = "2.0.0"
|
4
|
+
s.summary = "Microframework for web applications."
|
5
|
+
s.description = "Cuba is a microframework for web applications."
|
6
6
|
s.authors = ["Michel Martens"]
|
7
7
|
s.email = ["michel@soveran.com"]
|
8
8
|
s.homepage = "http://github.com/soveran/cuba"
|
9
|
-
s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cuba/ron.rb", "lib/cuba/test.rb", "lib/cuba/version.rb", "lib/cuba.rb", "cuba.gemspec", "test/accept.rb", "test/captures.rb", "test/composition.rb", "test/extension.rb", "test/helper.rb", "test/host.rb", "test/integration.rb", "test/match.rb", "test/number.rb", "test/on.rb", "test/path.rb", "test/run.rb", "test/segment.rb"]
|
9
|
+
s.files = ["LICENSE", "README.markdown", "Rakefile", "lib/cuba/ron.rb", "lib/cuba/test.rb", "lib/cuba/version.rb", "lib/cuba.rb", "cuba.gemspec", "test/accept.rb", "test/captures.rb", "test/composition.rb", "test/extension.rb", "test/helper.rb", "test/host.rb", "test/integration.rb", "test/match.rb", "test/number.rb", "test/on.rb", "test/param.rb", "test/path.rb", "test/run.rb", "test/segment.rb"]
|
10
10
|
s.add_dependency "rack", "~> 1.2"
|
11
11
|
s.add_dependency "tilt", "~> 1.2"
|
12
12
|
s.add_development_dependency "cutest", "~> 1.0"
|
data/lib/cuba/ron.rb
CHANGED
@@ -151,7 +151,7 @@ module Cuba
|
|
151
151
|
end
|
152
152
|
private :consume
|
153
153
|
|
154
|
-
def match(matcher, segment = "([
|
154
|
+
def match(matcher, segment = "([^\\/]+)")
|
155
155
|
case matcher
|
156
156
|
when String then consume(matcher.gsub(/:\w+/, segment))
|
157
157
|
when Regexp then consume(matcher)
|
@@ -181,12 +181,12 @@ module Cuba
|
|
181
181
|
# on "signup", param("user") do |atts|
|
182
182
|
# User.create(atts)
|
183
183
|
# end
|
184
|
-
def param(key
|
185
|
-
lambda { captures <<
|
184
|
+
def param(key)
|
185
|
+
lambda { captures << req[key] unless req[key].to_s.empty? }
|
186
186
|
end
|
187
187
|
|
188
|
-
def header(key
|
189
|
-
lambda { env[key.upcase.tr("-","_")]
|
188
|
+
def header(key)
|
189
|
+
lambda { env[key.upcase.tr("-","_")] }
|
190
190
|
end
|
191
191
|
|
192
192
|
# Useful for matching against the request host (i.e. HTTP_HOST).
|
@@ -209,7 +209,7 @@ module Cuba
|
|
209
209
|
# end
|
210
210
|
def accept(mimetype)
|
211
211
|
lambda do
|
212
|
-
env["HTTP_ACCEPT"].split(",").any? { |s| s.strip == mimetype } and
|
212
|
+
String(env["HTTP_ACCEPT"]).split(",").any? { |s| s.strip == mimetype } and
|
213
213
|
res["Content-Type"] = mimetype
|
214
214
|
end
|
215
215
|
end
|
data/lib/cuba/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Cuba
|
2
|
-
VERSION = "2.0.0
|
3
|
-
end
|
2
|
+
VERSION = "2.0.0"
|
3
|
+
end
|
data/test/accept.rb
CHANGED
@@ -14,3 +14,21 @@ test "accept mimetypes" do
|
|
14
14
|
|
15
15
|
assert_equal ["application/xml"], resp.body
|
16
16
|
end
|
17
|
+
|
18
|
+
test "tests don't fail when you don't specify an accept type" do
|
19
|
+
Cuba.define do
|
20
|
+
on accept("application/xml") do
|
21
|
+
res.write res["Content-Type"]
|
22
|
+
end
|
23
|
+
|
24
|
+
on default do
|
25
|
+
res.write "Default action"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
env = { "SCRIPT_NAME" => "/", "PATH_INFO" => "/post" }
|
30
|
+
|
31
|
+
_, _, resp = Cuba.call({})
|
32
|
+
|
33
|
+
assert_equal ["Default action"], resp.body
|
34
|
+
end
|
data/test/captures.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
-
require "stringio"
|
3
2
|
|
4
3
|
test "doesn't yield HOST" do
|
5
4
|
Cuba.define do
|
@@ -89,22 +88,6 @@ test "yield a file name with a matching extension" do
|
|
89
88
|
assert_equal ["app"], resp.body
|
90
89
|
end
|
91
90
|
|
92
|
-
test "yields a param" do
|
93
|
-
Cuba.define do
|
94
|
-
on get, "signup", param("email") do |email|
|
95
|
-
res.write email
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
|
100
|
-
"SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
|
101
|
-
"QUERY_STRING" => "email=john@doe.com" }
|
102
|
-
|
103
|
-
_, _, resp = Cuba.call(env)
|
104
|
-
|
105
|
-
assert_equal ["john@doe.com"], resp.body
|
106
|
-
end
|
107
|
-
|
108
91
|
test "yields a segment per nested block" do
|
109
92
|
Cuba.define do
|
110
93
|
on :one do |one|
|
data/test/param.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path("helper", File.dirname(__FILE__))
|
2
|
+
require "stringio"
|
3
|
+
|
4
|
+
prepare do
|
5
|
+
Cuba.define do
|
6
|
+
on get, "signup", param("email") do |email|
|
7
|
+
res.write email
|
8
|
+
end
|
9
|
+
|
10
|
+
on default do
|
11
|
+
res.write "No email"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test "yields a param" do
|
17
|
+
env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
|
18
|
+
"SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
|
19
|
+
"QUERY_STRING" => "email=john@doe.com" }
|
20
|
+
|
21
|
+
_, _, resp = Cuba.call(env)
|
22
|
+
|
23
|
+
assert_equal ["john@doe.com"], resp.body
|
24
|
+
end
|
25
|
+
|
26
|
+
test "doesn't yield a missing param" do
|
27
|
+
env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
|
28
|
+
"SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
|
29
|
+
"QUERY_STRING" => "" }
|
30
|
+
|
31
|
+
_, _, resp = Cuba.call(env)
|
32
|
+
|
33
|
+
assert_equal ["No email"], resp.body
|
34
|
+
end
|
35
|
+
|
36
|
+
test "doesn't yield an empty param" do
|
37
|
+
env = { "REQUEST_METHOD" => "GET", "PATH_INFO" => "/signup",
|
38
|
+
"SCRIPT_NAME" => "/", "rack.input" => StringIO.new,
|
39
|
+
"QUERY_STRING" => "email=" }
|
40
|
+
|
41
|
+
_, _, resp = Cuba.call(env)
|
42
|
+
|
43
|
+
assert_equal ["No email"], resp.body
|
44
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cuba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
version: 2.0.0
|
4
|
+
prerelease:
|
5
|
+
version: 2.0.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Michel Martens
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-03-
|
13
|
+
date: 2011-03-18 00:00:00 -03:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -57,7 +57,7 @@ dependencies:
|
|
57
57
|
version: "0.4"
|
58
58
|
type: :development
|
59
59
|
version_requirements: *id004
|
60
|
-
description: Cuba is a
|
60
|
+
description: Cuba is a microframework for web applications.
|
61
61
|
email:
|
62
62
|
- michel@soveran.com
|
63
63
|
executables: []
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- test/match.rb
|
86
86
|
- test/number.rb
|
87
87
|
- test/on.rb
|
88
|
+
- test/param.rb
|
88
89
|
- test/path.rb
|
89
90
|
- test/run.rb
|
90
91
|
- test/segment.rb
|
@@ -106,15 +107,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
106
107
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
108
|
none: false
|
108
109
|
requirements:
|
109
|
-
- - "
|
110
|
+
- - ">="
|
110
111
|
- !ruby/object:Gem::Version
|
111
|
-
version:
|
112
|
+
version: "0"
|
112
113
|
requirements: []
|
113
114
|
|
114
115
|
rubyforge_project:
|
115
116
|
rubygems_version: 1.6.0
|
116
117
|
signing_key:
|
117
118
|
specification_version: 3
|
118
|
-
summary:
|
119
|
+
summary: Microframework for web applications.
|
119
120
|
test_files: []
|
120
121
|
|