watts 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/Rakefile +7 -4
- data/doc/LICENSE +1 -1
- data/doc/TODO +5 -0
- data/doc/examples/README +1 -1
- data/lib/watts.rb +29 -14
- metadata +15 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e1090395dfbb1d65792a782eed0d9dbc90f3fed7
|
4
|
+
data.tar.gz: 23150b42d9ace03b338056648de0d67ee8d4174b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 97165d036da3a810ddf8bcea7296d0c426adbe5b0cc968bd3d000e9ef07338c6d7b255e30a26ea89521d9ba1a6505fb8c2a598d550a1a09c21e382d923886cf4
|
7
|
+
data.tar.gz: 0f7325024edf7b709b16071fe385a6be7cc0be9c09aa428154020fd265c059eb65a5f3a862b278bab816ebbd4d829917d718d6a93a1db187d933707cdba19bab
|
data/Rakefile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'rubygems/package_task'
|
2
2
|
require 'rdoc/task'
|
3
3
|
|
4
4
|
$: << "#{File.dirname(__FILE__)}/lib"
|
@@ -20,9 +20,9 @@ spec = Gem::Specification.new { |s|
|
|
20
20
|
s.name = 'watts'
|
21
21
|
s.summary =
|
22
22
|
"Resource-oriented, Rack-based, minimalist web framework."
|
23
|
-
s.homepage = "http://
|
23
|
+
s.homepage = "http://github.com/pete/watts"
|
24
24
|
%w().each &s.method(:add_dependency)
|
25
|
-
s.version = '1.0.
|
25
|
+
s.version = '1.0.4'
|
26
26
|
}
|
27
27
|
|
28
28
|
Rake::RDocTask.new(:doc) { |t|
|
@@ -33,7 +33,7 @@ Rake::RDocTask.new(:doc) { |t|
|
|
33
33
|
t.rdoc_dir = 'doc/rdoc'
|
34
34
|
}
|
35
35
|
|
36
|
-
|
36
|
+
Gem::PackageTask.new(spec) { |pkg|
|
37
37
|
pkg.need_tar_bz2 = true
|
38
38
|
}
|
39
39
|
desc "Cleans out the packaged files."
|
@@ -55,5 +55,8 @@ task(:irb) {
|
|
55
55
|
desc "Runs tests."
|
56
56
|
task(:test) {
|
57
57
|
tests = Dir['test/*_test.rb'].map { |t| "-r#{t}" }
|
58
|
+
if ENV['COVERAGE']
|
59
|
+
tests.unshift "-rtest/coverage"
|
60
|
+
end
|
58
61
|
system 'ruby', '-Ilib', '-I.', *tests, '-e', ''
|
59
62
|
}
|
data/doc/LICENSE
CHANGED
data/doc/TODO
CHANGED
@@ -1,2 +1,7 @@
|
|
1
1
|
Perhaps use Rack::URLMap where applicable (and transparent) to speed things up,
|
2
2
|
provided it doesn't preclude things like changing the app on the fly.
|
3
|
+
|
4
|
+
Tweaks to make inheritance behave better.
|
5
|
+
|
6
|
+
Hooks? I keep running into places where I'd like to have them, but a clean way
|
7
|
+
to do this is not yet obvious.
|
data/doc/examples/README
CHANGED
data/lib/watts.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
%w(
|
2
2
|
forwardable
|
3
3
|
rack
|
4
|
+
set
|
4
5
|
watts/monkey_patching
|
5
6
|
).each &method(:require)
|
6
7
|
|
@@ -74,6 +75,18 @@ module Watts
|
|
74
75
|
["501 Not Implemented.\n"]],
|
75
76
|
}
|
76
77
|
|
78
|
+
# The "empty" set.
|
79
|
+
ESet = Set.new(['/', ''])
|
80
|
+
|
81
|
+
# Method name cache. Maps HTTP methods to object methods.
|
82
|
+
MNCache = Hash.new { |h,k|
|
83
|
+
h[k] = k.downcase.to_sym
|
84
|
+
}
|
85
|
+
# Prefill MNCache above with the likely culprits:
|
86
|
+
%w(
|
87
|
+
GET PUT POST DELETE OPTIONS HEAD TRACE CONNECT PATCH
|
88
|
+
).each &MNCache.method(:'[]')
|
89
|
+
|
77
90
|
class << self
|
78
91
|
attr_new Hash, :http_methods
|
79
92
|
attr_new Watts::Path, :path_map
|
@@ -83,11 +96,10 @@ module Watts
|
|
83
96
|
|
84
97
|
def self.decypher_path p
|
85
98
|
return p if p.kind_of?(Array)
|
86
|
-
return [] if
|
99
|
+
return [] if ESet.include?(p)
|
87
100
|
return [p] if p.kind_of?(Regexp)
|
88
|
-
p
|
89
|
-
|
90
|
-
end
|
101
|
+
p.split('/').tap { |a| a.reject!(&''.method(:'==')) }
|
102
|
+
end
|
91
103
|
|
92
104
|
to_instance :path_map, :decypher_path, :path_to
|
93
105
|
|
@@ -139,6 +151,8 @@ module Watts
|
|
139
151
|
end
|
140
152
|
res
|
141
153
|
end
|
154
|
+
# And because res(...) is a little less distracting than resource(...):
|
155
|
+
class << self; alias_method :res, :resource; end
|
142
156
|
|
143
157
|
# Given a resource (and, optionally, arguments if the path requires
|
144
158
|
# them), this method returns an absolute path to the resource.
|
@@ -154,15 +168,15 @@ module Watts
|
|
154
168
|
|
155
169
|
# Our interaction with Rack.
|
156
170
|
def call env, req_path = nil
|
157
|
-
rm = env['REQUEST_METHOD']
|
171
|
+
rm = MNCache[env['REQUEST_METHOD']]
|
158
172
|
return(Errors[501]) unless Resource::HTTPMethods.include?(rm)
|
159
173
|
|
160
174
|
req_path ||= decypher_path env['PATH_INFO']
|
161
|
-
resource_class, args = match req_path
|
175
|
+
resource_class, args = path_map.match req_path, []
|
162
176
|
|
163
177
|
if resource_class
|
164
|
-
env
|
165
|
-
res = resource_class.new
|
178
|
+
env[:watts_app] ||= self
|
179
|
+
res = resource_class.new env
|
166
180
|
res.send(rm, *args)
|
167
181
|
else
|
168
182
|
Errors[404]
|
@@ -199,7 +213,7 @@ module Watts
|
|
199
213
|
# (for OPTIONS) manually. Have a look at the README and doc/examples.
|
200
214
|
class Resource
|
201
215
|
HTTPMethods =
|
202
|
-
[:get, :post, :put, :delete, :head, :options, :trace, :connect]
|
216
|
+
Set.new([:get, :post, :put, :delete, :head, :options, :trace, :connect])
|
203
217
|
|
204
218
|
class << self
|
205
219
|
attr_new Array, :http_methods
|
@@ -211,21 +225,23 @@ module Watts
|
|
211
225
|
HTTPMethods.each { |http_method|
|
212
226
|
define_singleton_method(http_method) { |&b|
|
213
227
|
(http_methods << http_method.to_s.upcase).uniq!
|
214
|
-
bmname = "__#{http_method}"
|
228
|
+
bmname = :"__#{http_method}"
|
215
229
|
define_method(bmname, &b)
|
216
230
|
define_method(http_method) { |*args|
|
217
231
|
begin
|
218
232
|
resp = send bmname, *args
|
219
233
|
rescue ArgumentError => e
|
220
234
|
# TODO: Arity/path args mismatch handler here.
|
235
|
+
# ...Maybe. It seems appropriate, but I've never
|
236
|
+
# needed it.
|
221
237
|
raise e
|
222
238
|
end
|
223
239
|
|
224
240
|
# TODO: Problems.
|
225
241
|
case resp
|
226
242
|
when nil
|
227
|
-
|
228
|
-
when Array
|
243
|
+
response
|
244
|
+
when Array, Rack::Response
|
229
245
|
resp
|
230
246
|
else
|
231
247
|
resp = resp.to_s
|
@@ -266,7 +282,7 @@ module Watts
|
|
266
282
|
|
267
283
|
to_instance :http_methods
|
268
284
|
attr_new Rack::Response, :response
|
269
|
-
attr_accessor :env, :
|
285
|
+
attr_accessor :env, :app
|
270
286
|
|
271
287
|
# Every resource, on being instantiated, is given the Rack env.
|
272
288
|
def initialize(env)
|
@@ -274,7 +290,6 @@ module Watts
|
|
274
290
|
self.app = app
|
275
291
|
end
|
276
292
|
self.env = env
|
277
|
-
self.response = Rack::Response.new
|
278
293
|
end
|
279
294
|
|
280
295
|
# The default options method, to comply with RFC 2616, returns a list
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: watts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Pete Elmore
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2016-11-01 00:00:00.000000000 Z
|
13
12
|
dependencies: []
|
14
13
|
description:
|
15
14
|
email: pete@debu.gs
|
@@ -19,38 +18,37 @@ extra_rdoc_files:
|
|
19
18
|
- doc/LICENSE
|
20
19
|
- doc/TODO
|
21
20
|
files:
|
22
|
-
-
|
23
|
-
-
|
21
|
+
- Rakefile
|
22
|
+
- doc/LICENSE
|
23
|
+
- doc/TODO
|
24
|
+
- doc/examples/README
|
24
25
|
- doc/examples/environment.ru
|
25
|
-
- doc/examples/hoshi.ru
|
26
26
|
- doc/examples/hello_world.ru
|
27
|
-
- doc/examples/
|
27
|
+
- doc/examples/hoshi.ru
|
28
28
|
- doc/examples/matching.ru
|
29
|
-
-
|
30
|
-
-
|
31
|
-
|
32
|
-
homepage: http://debu.gs/watts
|
29
|
+
- lib/watts.rb
|
30
|
+
- lib/watts/monkey_patching.rb
|
31
|
+
homepage: http://github.com/pete/watts
|
33
32
|
licenses: []
|
33
|
+
metadata: {}
|
34
34
|
post_install_message:
|
35
35
|
rdoc_options: []
|
36
36
|
require_paths:
|
37
37
|
- lib
|
38
38
|
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
39
|
requirements:
|
41
|
-
- -
|
40
|
+
- - ">="
|
42
41
|
- !ruby/object:Gem::Version
|
43
42
|
version: '0'
|
44
43
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
-
none: false
|
46
44
|
requirements:
|
47
|
-
- -
|
45
|
+
- - ">="
|
48
46
|
- !ruby/object:Gem::Version
|
49
47
|
version: '0'
|
50
48
|
requirements: []
|
51
49
|
rubyforge_project:
|
52
|
-
rubygems_version:
|
50
|
+
rubygems_version: 2.5.1
|
53
51
|
signing_key:
|
54
|
-
specification_version:
|
52
|
+
specification_version: 4
|
55
53
|
summary: Resource-oriented, Rack-based, minimalist web framework.
|
56
54
|
test_files: []
|