watts 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ spec = Gem::Specification.new { |s|
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.6'
25
+ s.version = '0.0.7'
26
26
  }
27
27
 
28
28
  Rake::RDocTask.new(:doc) { |t|
data/doc/TODO CHANGED
@@ -0,0 +1,2 @@
1
+ Perhaps use Rack::URLMap where applicable (and transparent) to speed things up,
2
+ provided it doesn't preclude things like changing the app on the fly.
data/doc/examples/README CHANGED
@@ -1,10 +1,11 @@
1
1
  All of the examples are standalone Watts applications, which you can run
2
- directly. They could all be pretty easily turned into rackup files.
2
+ directly. To run them, you can use the command.
3
+ rackup file.ru
3
4
 
4
- hello_world.rb is the most basic demonstration.
5
- matching.rb shows how Watts's pattern-matching works.
6
- hoshi.rb is a demonstration of the view-wrapping resource.
7
- environment.rb shows what you have to work with in your request.
5
+ * hello_world.ru is the most basic demonstration.
6
+ * matching.ru shows how Watts's pattern-matching works.
7
+ * hoshi.ru is a demonstration of the view-wrapping resource.
8
+ * environment.ru shows what you have to work with in your request.
8
9
 
9
10
  Although they're all single-file applications, there's nothing that
10
11
  prevents you from splitting things up arbitrarily. It's all just Ruby.
@@ -1,4 +1,3 @@
1
- #!/usr/bin/env ruby
2
1
  # This example gives you a feel for the environment in which Watts::Resources
3
2
  # run. By "environment", of course, I really just mean that the 'env' value
4
3
  # Rack gives you on requests is accessible from inside your resources. You can
@@ -34,5 +33,4 @@ end
34
33
 
35
34
  app = WattsEnvironment.new
36
35
  builder = Rack::Builder.new { run app }
37
-
38
- Rack::Handler::Mongrel.run builder, :Port => 8080
36
+ run builder
@@ -14,5 +14,4 @@ end
14
14
 
15
15
  app = Simple.new
16
16
  builder = Rack::Builder.new { run app }
17
-
18
- Rack::Handler::Mongrel.run builder, :Port => 8080
17
+ run builder
@@ -27,5 +27,4 @@ end
27
27
 
28
28
  app = HelloHTML.new
29
29
  builder = Rack::Builder.new { run app }
30
-
31
- Rack::Handler::Mongrel.run builder, :Port => 8080
30
+ run builder
data/lib/watts.rb CHANGED
@@ -70,6 +70,9 @@ module Watts
70
70
  [400, {'Content-Type' => 'text/plain'}, ["400 Bad Request.\n"]],
71
71
  404 =>
72
72
  [404, {'Content-Type' => 'text/plain'}, ["404 Not Found\n"]],
73
+ 501 =>
74
+ [501, {'Content-Type' => 'text/plain'},
75
+ ["501 Not Implemented.\n"]],
73
76
  }
74
77
 
75
78
  class << self
@@ -153,7 +156,7 @@ module Watts
153
156
  # Our interaction with Rack.
154
157
  def call env, req_path = nil
155
158
  rm = env['REQUEST_METHOD'].downcase.to_sym
156
- return(Errors[400]) unless Resource::HTTPMethods.include?(rm)
159
+ return(Errors[501]) unless Resource::HTTPMethods.include?(rm)
157
160
 
158
161
  req_path ||= decypher_path env['PATH_INFO']
159
162
  resource_class, args = match req_path
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: 19
5
4
  prerelease: false
6
5
  segments:
7
6
  - 0
8
7
  - 0
9
- - 6
10
- version: 0.0.6
8
+ - 7
9
+ version: 0.0.7
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: 2011-03-15 00:00:00 -07:00
17
+ date: 2011-08-01 00:00:00 -07: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"
@@ -45,11 +43,10 @@ files:
45
43
  - lib/watts.rb
46
44
  - lib/watts/monkey_patching.rb
47
45
  - doc/TODO
48
- - doc/examples/hello_world.rb
49
- - doc/examples/environment.rb
46
+ - doc/examples/hoshi.ru
47
+ - doc/examples/environment.ru
50
48
  - doc/examples/README
51
- - doc/examples/matching.rb
52
- - doc/examples/hoshi.rb
49
+ - doc/examples/hello_world.ru
53
50
  - doc/examples/matching.ru
54
51
  - doc/LICENSE
55
52
  - Rakefile
@@ -67,7 +64,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
64
  requirements:
68
65
  - - ">="
69
66
  - !ruby/object:Gem::Version
70
- hash: 3
71
67
  segments:
72
68
  - 0
73
69
  version: "0"
@@ -76,7 +72,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
72
  requirements:
77
73
  - - ">="
78
74
  - !ruby/object:Gem::Version
79
- hash: 3
80
75
  segments:
81
76
  - 0
82
77
  version: "0"
@@ -1,61 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # An illustration of the pattern-matching capabilities of Watts. Some URLs to
3
- # try if you start this one up:
4
- # http://localhost:8080/strlen/foo (Which should tell you '3'.)
5
- # http://localhost:8080/fib/15 (Which should give you 987.)
6
- # http://localhost:8080/fib/foo (Which is a 404. 'foo' isn't a number!)
7
- # http://localhost:8080/fib/f (Which should give you 0x3db.)
8
- # http://localhost:8080/fib/0x15 (Which should give you 0x452f.)
9
-
10
- require 'watts'
11
-
12
- class MatchingDemo < Watts::App
13
- class Strlen < Watts::Resource
14
- # Takes an argument, and just returns the length of the argument.
15
- get { |str| str.length.to_s + "\n" }
16
- end
17
-
18
- class Fibonacci < Watts::Resource
19
- # This resource takes an argument for GET. It is filled in by Watts
20
- # according to the argument pattern passed into resource below.
21
- get { |n| fib(n.to_i).to_s + "\n" }
22
-
23
- # A naive, recursive, slow, text-book implementation of Fibonacci.
24
- def fib(n)
25
- if n < 2
26
- 1
27
- else
28
- fib(n - 1) + fib(n - 2)
29
- end
30
- end
31
- end
32
-
33
- # As above, but with a base-16 number.
34
- class HexFibonacci < Fibonacci
35
- get { |n| "0x" + fib(n.to_i(16)).to_s(16) + "\n" }
36
- end
37
-
38
- resource('/') {
39
- # A symbol can be used to indicate an 'argument' component of a path,
40
- # which is in turn passed to the resource's method as paths. It will
41
- # match anything, making it almost equivalent to just using an empty
42
- # regex (see below), except that it can serve as documentation.
43
- resource(['strlen', :str], Strlen)
44
-
45
- resource('fib') {
46
- # You can match arguments based on a regex. The path component for
47
- # the regex is passed to the resource's method as part of the
48
- # argument list.
49
- resource([/^[0-9]+$/], Fibonacci)
50
-
51
- # As above, but here we use hexadecimal. If the pattern for
52
- # Fibonacci doesn't match, then we'll end up hitting this one.
53
- resource([/^(0x)?[0-9a-f]+$/i], HexFibonacci)
54
- }
55
- }
56
- end
57
-
58
- app = MatchingDemo.new
59
- builder = Rack::Builder.new { run app }
60
-
61
- Rack::Handler::Mongrel.run builder, :Port => 8080