watts 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/doc/examples/matching.ru +60 -0
  3. data/lib/watts.rb +1 -1
  4. metadata +8 -3
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.5'
25
+ s.version = '0.0.6'
26
26
  }
27
27
 
28
28
  Rake::RDocTask.new(:doc) { |t|
@@ -0,0 +1,60 @@
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
+ run builder
data/lib/watts.rb CHANGED
@@ -155,7 +155,7 @@ module Watts
155
155
  rm = env['REQUEST_METHOD'].downcase.to_sym
156
156
  return(Errors[400]) unless Resource::HTTPMethods.include?(rm)
157
157
 
158
- req_path ||= decypher_path env['REQUEST_PATH']
158
+ req_path ||= decypher_path env['PATH_INFO']
159
159
  resource_class, args = match req_path
160
160
 
161
161
  if resource_class
metadata CHANGED
@@ -1,12 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: watts
3
3
  version: !ruby/object:Gem::Version
4
+ hash: 19
4
5
  prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 0
8
- - 5
9
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
10
11
  platform: ruby
11
12
  authors:
12
13
  - Pete Elmore
@@ -14,7 +15,7 @@ autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
17
 
17
- date: 2011-03-10 00:00:00 -08:00
18
+ date: 2011-03-15 00:00:00 -07:00
18
19
  default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
@@ -25,6 +26,7 @@ dependencies:
25
26
  requirements:
26
27
  - - ">="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 3
28
30
  segments:
29
31
  - 0
30
32
  version: "0"
@@ -48,6 +50,7 @@ files:
48
50
  - doc/examples/README
49
51
  - doc/examples/matching.rb
50
52
  - doc/examples/hoshi.rb
53
+ - doc/examples/matching.ru
51
54
  - doc/LICENSE
52
55
  - Rakefile
53
56
  has_rdoc: true
@@ -64,6 +67,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
64
67
  requirements:
65
68
  - - ">="
66
69
  - !ruby/object:Gem::Version
70
+ hash: 3
67
71
  segments:
68
72
  - 0
69
73
  version: "0"
@@ -72,6 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
76
  requirements:
73
77
  - - ">="
74
78
  - !ruby/object:Gem::Version
79
+ hash: 3
75
80
  segments:
76
81
  - 0
77
82
  version: "0"