watts 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +7 -2
- data/lib/watts.rb +34 -3
- metadata +4 -8
data/Rakefile
CHANGED
@@ -19,10 +19,10 @@ spec = Gem::Specification.new { |s|
|
|
19
19
|
|
20
20
|
s.name = 'watts'
|
21
21
|
s.summary =
|
22
|
-
"
|
22
|
+
"Resource-oriented, Rack-based, minimalist web framework."
|
23
23
|
s.homepage = "http://debu.gs/#{s.name}"
|
24
24
|
%w(metaid).each &s.method(:add_dependency)
|
25
|
-
s.version = '0.0.
|
25
|
+
s.version = '0.0.3'
|
26
26
|
}
|
27
27
|
|
28
28
|
Rake::RDocTask.new(:doc) { |t|
|
@@ -51,3 +51,8 @@ desc "Runs IRB, automatically require()ing #{spec.name}."
|
|
51
51
|
task(:irb) {
|
52
52
|
exec "irb -Ilib -r#{spec.name}"
|
53
53
|
}
|
54
|
+
|
55
|
+
desc "Runs tests."
|
56
|
+
task(:test) {
|
57
|
+
system "ruby -Ilib test/*_test.rb"
|
58
|
+
}
|
data/lib/watts.rb
CHANGED
@@ -18,7 +18,7 @@ module Watts
|
|
18
18
|
|
19
19
|
def match path, args
|
20
20
|
if path.empty?
|
21
|
-
[resource, args]
|
21
|
+
[resource, args] if resource
|
22
22
|
elsif(sub = self[path[0]])
|
23
23
|
sub.match(path[1..-1], args)
|
24
24
|
else
|
@@ -36,6 +36,28 @@ module Watts
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
def rmatch res, args, acc = []
|
40
|
+
return "/#{acc.join('/')}" if args.empty? && resource == res
|
41
|
+
|
42
|
+
rest = args[1..-1]
|
43
|
+
accnext = acc.dup << args[0]
|
44
|
+
|
45
|
+
each { |k,sub|
|
46
|
+
t = sub.rmatch res, args, [k] + acc
|
47
|
+
return t if t
|
48
|
+
|
49
|
+
if k.kind_of?(Regexp) && k.match(args[0])
|
50
|
+
t = sub.rmatch res, rest, accnext
|
51
|
+
return t if t
|
52
|
+
elsif k.kind_of?(Symbol)
|
53
|
+
t = sub.rmatch res, rest, accnext
|
54
|
+
return t if t
|
55
|
+
end
|
56
|
+
}
|
57
|
+
|
58
|
+
nil
|
59
|
+
end
|
60
|
+
|
39
61
|
def_delegators :sub_paths, :'[]', :'[]=', :each
|
40
62
|
end
|
41
63
|
|
@@ -60,11 +82,12 @@ module Watts
|
|
60
82
|
def self.decypher_path p
|
61
83
|
return p if p.kind_of?(Array)
|
62
84
|
return [] if ['/', ''].include?(p)
|
85
|
+
return [p] if p.kind_of?(Regexp)
|
63
86
|
p = p.split('/')
|
64
87
|
p.select { |sub| sub != '' }
|
65
88
|
end
|
66
89
|
|
67
|
-
to_instance :path_map, :decypher_path
|
90
|
+
to_instance :path_map, :decypher_path, :path_to
|
68
91
|
|
69
92
|
# If you want your Watts application to do anything at all, you're very
|
70
93
|
# likely to want to call this method at least once. The basic purpose
|
@@ -115,6 +138,12 @@ module Watts
|
|
115
138
|
res
|
116
139
|
end
|
117
140
|
|
141
|
+
# Given a resource (and, optionally, arguments if the path requires
|
142
|
+
# them), this method returns an absolute path to the resource.
|
143
|
+
def self.path_to res, *args
|
144
|
+
path_map.rmatch res, args
|
145
|
+
end
|
146
|
+
|
118
147
|
# Given a path, returns the matching resource, if any.
|
119
148
|
def match req_path
|
120
149
|
req_path = decypher_path req_path
|
@@ -249,7 +278,9 @@ module Watts
|
|
249
278
|
# By default, we return "405 Method Not Allowed" and set the Allow:
|
250
279
|
# header appropriately.
|
251
280
|
def default_http_method(*args)
|
252
|
-
[405,
|
281
|
+
[405,
|
282
|
+
{ 'Allow' => http_methods.join(', ') },
|
283
|
+
['Method not allowed.']]
|
253
284
|
end
|
254
285
|
end
|
255
286
|
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 27
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Pete Elmore
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date:
|
17
|
+
date: 2011-01-27 00:00:00 -08:00
|
19
18
|
default_executable:
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
@@ -26,7 +25,6 @@ dependencies:
|
|
26
25
|
requirements:
|
27
26
|
- - ">="
|
28
27
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 3
|
30
28
|
segments:
|
31
29
|
- 0
|
32
30
|
version: "0"
|
@@ -66,7 +64,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
64
|
requirements:
|
67
65
|
- - ">="
|
68
66
|
- !ruby/object:Gem::Version
|
69
|
-
hash: 3
|
70
67
|
segments:
|
71
68
|
- 0
|
72
69
|
version: "0"
|
@@ -75,7 +72,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
72
|
requirements:
|
76
73
|
- - ">="
|
77
74
|
- !ruby/object:Gem::Version
|
78
|
-
hash: 3
|
79
75
|
segments:
|
80
76
|
- 0
|
81
77
|
version: "0"
|
@@ -85,6 +81,6 @@ rubyforge_project:
|
|
85
81
|
rubygems_version: 1.3.7
|
86
82
|
signing_key:
|
87
83
|
specification_version: 3
|
88
|
-
summary:
|
84
|
+
summary: Resource-oriented, Rack-based, minimalist web framework.
|
89
85
|
test_files: []
|
90
86
|
|