We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Rubygem
Description: Resource-oriented open source Ruby framework for Web apps.
Homepage: http://rubywaves.com/
Clone URL: git://github.com/dyoder/waves.git
Replaced selector with cascading resources. Updated error handling to look 
a bit nicer.
dyoder (author)
Sat Sep 20 12:39:56 -0700 2008
commit  c5731d0a1a0de190be8f89b4ca0901c23588b8fd
tree    5e7453c3488b1117762be79838b9a607ca63fd1b
parent  964fda9ac525515fdd1dbd4ec1afc02630d82926
...
33
34
35
36
37
 
38
39
40
41
 
42
43
44
45
46
 
47
48
49
50
51
52
53
54
55
...
33
34
35
 
 
36
37
38
39
 
40
41
42
43
44
 
45
46
47
48
49
50
 
51
52
53
0
@@ -33,23 +33,21 @@ module Waves
0
         # set a default content type -- this can be overridden by the resource
0
         request.response.content_type = request.accept.default
0
         # grab the appropriate resource from those declared in the configuration, based on the request
0
- resource = Waves.config.resources[ request ]
0
- Waves::Logger.debug "Directing request to #{resource.class.name}"
0
+ resource = Waves.config.resource.new( request )
0
         begin
0
           # invoke the request method, wrapped by the before and after methods
0
           resource.before
0
- content = resource.send( request.method )
0
+ request.response.body = resource.send( request.method )
0
           resource.after
0
         rescue Exception => e
0
           # handle any exceptions using the resource handlers, if any
0
           Waves::Logger.info e.to_s
0
- resource.handler( e ) rescue raise e
0
+ ( request.response.body = resource.handler( e ) ) rescue raise e
0
         ensure
0
           # no matter what happens, also run the resource's always method
0
           resource.always
0
         end
0
         # okay, we've handled the request, now write the response unless it was already done
0
- request.response.write( content.to_s )
0
         request.response.finish
0
       end
0
 
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@ module Waves
0
       # used to provide consisting matching logic across all matchers
0
       def test( request )
0
         constraints.all? do | key, val |
0
- if val.nil?
0
+ if val.nil? or val == true
0
             true
0
           else
0
             if val.respond_to? :call
...
12
13
14
 
15
16
17
...
44
45
46
47
 
48
49
50
...
12
13
14
15
16
17
18
...
45
46
47
 
48
49
50
51
0
@@ -12,6 +12,7 @@ module Waves
0
       def initialize( pattern ) ; @pattern = pattern ; end
0
       
0
       def call( request )
0
+ return {} if @pattern == true
0
         path = extract_path( request ).reverse
0
         return {} if ( @pattern.nil? or @pattern == false or ( path.empty? and @pattern.empty? ) )
0
         capture = {}
0
@@ -44,7 +45,7 @@ module Waves
0
 
0
       # just a little helper method
0
       def extract_path( request )
0
- path = ( request.traits.waves.rest || request.traits.waves.path )
0
+ path = request.traits.waves.path
0
         return path if path
0
         path = request.path.split('/')
0
         path.shift unless path.empty?
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ module Waves
0
         @uri = Matchers::URI.new( options )
0
         @constraints = {
0
           :content_type => Matchers::ContentType.new( options[ :content_type ] ),
0
- :accept => Matchers::Accepts.new( options ),
0
+ :accept => Matchers::Accept.new( options ),
0
           :query => Matchers::Query.new( options[:query] ),
0
           :traits => Matchers::Traits.new( options[:traits] )
0
         }
...
15
16
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
23
24
25
26
 
27
28
29
30
31
 
32
33
34
...
38
39
40
 
 
 
41
42
43
 
 
44
45
46
...
57
58
59
 
 
 
 
 
 
 
 
 
60
61
62
...
15
16
17
 
 
 
 
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
 
 
42
43
44
 
 
 
45
46
47
48
...
52
53
54
55
56
57
58
59
 
60
61
62
63
64
...
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
0
@@ -15,20 +15,34 @@ module Waves
0
           def self.singular ; basename.downcase ; end
0
           def self.plural ; basename.downcase.plural ; end
0
           def self.with( options ) ; @options = options ; yield ; @options = nil ; end
0
- def self.on( method, path, options = {}, &block )
0
- options.merge!( @options ) if @options
0
- options[ :path ] = ( path.is_a? Hash and path.values.first ) or path
0
- functor_with_self( method, Waves::Matchers::Resource.new( options ), &block )
0
+ def self.on( method, path = true, options = nil, &block )
0
+ if path.is_a? Hash
0
+ generator = path.keys.first
0
+ path = path.values.first
0
+ end
0
+ if options
0
+ options[ :path ] = path
0
+ else
0
+ options = { :path => path }
0
+ end
0
+ options = @options.merge( options ) if @options
0
+ matcher = Waves::Matchers::Resource.new( options )
0
+ methods = case method
0
+ when nil then nil
0
+ when true then [ :post, :get, :put, :delete ]
0
+ when Array then method
0
+ else [ method ]
0
+ end
0
+ methods.each do | method |
0
+ functor_with_self( method, matcher, &block )
0
+ end
0
+ # define generator method
0
           end
0
           def self.before( path = nil, options = {}, &block )
0
- options.merge!( @options ) if @options
0
- options[ :path ] = path
0
- functor_with_self( :before, Waves::Matchers::Resource.new( options ), &block )
0
+ on( :before, path, options, &block )
0
           end
0
           def self.after( path = nil, options = {}, &block )
0
- options.merge!( @options ) if @options
0
- options[ :path ] = path
0
- functor_with_self( :after, Waves::Matchers::Resource.new( options ), &block )
0
+ on( :after, path, options, &block )
0
           end
0
           def self.wrap( path = nil, options = {}, &block )
0
             before( path, options, &block )
0
@@ -38,9 +52,13 @@ module Waves
0
           def self.always( &block ) ; define_method( :always, &block ) ; end
0
           
0
           before {} ; after {} ; always {}
0
+ %w( post get put delete ).each do | method |
0
+ on( method ) { not_found }
0
+ end
0
           
0
           handler( Waves::Dispatchers::NotFoundError ) do | e |
0
- response.status = 404; response.body = 'Not Found!'
0
+ response.status = 404; response.content_type = 'text/html'
0
+ Waves::Views::Errors.process( request ) { not_found_404 }
0
           end
0
 
0
         end
0
@@ -57,6 +75,15 @@ module Waves
0
           self.class::Paths.new( request )
0
         end
0
       end
0
+ def to( resource )
0
+ resource = case resource
0
+ when Base
0
+ resource
0
+ when Symbol, String
0
+ Waves.main::Resources[ resource ]
0
+ end
0
+ resource.new( request ).send( request.method )
0
+ end
0
       def redirect( path ) ; request.redirect( path ) ; end
0
       def render( path, assigns = {} ) ; Waves::Views::Base.process( request ) { render( path, assigns ) }; end
0
     end
...
142
143
144
145
 
146
147
148
...
174
175
176
177
178
179
180
181
182
183
184
185
...
142
143
144
 
145
146
147
148
...
174
175
176
 
 
 
 
 
 
177
178
179
0
@@ -142,7 +142,7 @@ module Waves
0
     # reloadable []
0
     class Default < Base
0
 
0
- %w( host port ports log reloadable database session debug root synchronize? dependencies ).
0
+ %w( host port ports log reloadable resource database session debug root synchronize? dependencies ).
0
       each { |name| attribute(name) }
0
 
0
       # Set the Rack handler, along with any specific options
0
@@ -174,12 +174,6 @@ module Waves
0
         end
0
       end
0
       
0
- def self.resources( &block )
0
- return self['resource'] unless block
0
- self['resource'] = selector = Waves::Resources::Selector.new
0
- selector.instance_eval( &block )
0
- end
0
-
0
       debug true ; synchronize? true
0
       session :duration => 30.minutes, :path => '/tmp/sessions'
0
       log :level => :info, :output => $stderr
...
107
108
109
110
111
112
113
...
107
108
109
 
110
111
112
0
@@ -107,7 +107,6 @@ module Waves
0
 
0
     end
0
 
0
- # I'm sorry ... :)
0
     class Base ; include Mixin ; end
0
 
0
   end
...
61
62
63
64
 
65
66
67
...
70
71
72
73
74
75
76
77
78
79
80
81
 
82
83
84
85
86
87
88
89
90
91
92
...
61
62
63
 
64
65
66
67
...
70
71
72
 
73
74
75
76
77
78
 
 
79
80
81
82
83
84
85
 
 
86
87
88
0
@@ -61,7 +61,7 @@ require 'runtime/configuration'
0
 
0
 # waves URI mapping
0
 require 'matchers/base'
0
-require 'matchers/accepts'
0
+require 'matchers/accept'
0
 require 'matchers/content_type'
0
 require 'matchers/path'
0
 require 'matchers/query'
0
@@ -70,23 +70,19 @@ require 'matchers/uri'
0
 require 'matchers/request'
0
 require 'matchers/resource'
0
 require 'resources/path'
0
-require 'resources/selector'
0
 require 'resources/mixin'
0
 require 'resources/delegate'
0
 
0
 # waves mvc support
0
 require 'controllers/mixin'
0
 require 'views/mixin'
0
-# require 'helpers/tag_helper'
0
-# require 'helpers/url_helper'
0
+require 'views/errors'
0
 require 'helpers/common'
0
 require 'helpers/form'
0
 require 'helpers/formatting'
0
 require 'helpers/model'
0
 require 'helpers/view'
0
 require 'helpers/built_in'
0
-# require 'helpers/asset_helper'
0
-# require 'helpers/number_helper'
0
 require 'renderers/mixin'
0
 require 'renderers/erubis'
0
 require 'renderers/markaby'

Comments

    No one has commented yet.