GitHub Sale: sign up for any paid plan this week and pay nothing until January 1, 2009!  [ 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
Rewriting the actual mapping DSL to use new mapping constructs.
dyoder (author)
Tue Jun 24 13:20:46 -0700 2008
commit  9ca295413e64ca27bcbab2335f558cf2fce72cab
tree    8e6d157aeff4c05e5fe9419c2eaaca0565bbf10b
parent  c20eee436e590e06afd629fb3caddeebed55dfb8
...
4
5
6
 
 
 
 
 
 
 
7
8
9
...
4
5
6
7
8
9
10
11
12
13
14
15
16
0
@@ -4,6 +4,13 @@ module Waves
0
     
0
     class Action
0
       
0
+ # TODO: Make this more generic and able to support Handler (or push add'l code into Handler).
0
+ # Should support anonymous blocks (i.e. that don't call a method on Resource), or cases where
0
+ # no path was provided. Should also always use :path rather than relying on target (this is
0
+ # actually code in patter), and add code for :scheme, :domain, etc. constraints (Constraints).
0
+ #
0
+ # Can some o the resource determination related code be factored out of there or simplified?
0
+
0
       attr_reader :name, :resource, :pattern, :constraints, :descriptors
0
       
0
       def initialize( options, &block )
...
2
3
4
 
 
5
6
 
7
8
9
10
11
12
13
14
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
 
 
 
 
 
 
 
 
49
50
51
...
54
55
56
 
 
 
 
 
57
58
59
60
...
2
3
4
5
6
7
 
8
9
10
11
12
13
 
 
 
 
 
 
 
 
 
 
 
14
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
...
48
49
50
51
52
53
54
55
56
57
58
59
0
@@ -2,50 +2,44 @@ module Waves
0
 
0
   module Mapping
0
     
0
+ include Functor::Method
0
+
0
     METHODS = %w( get put post delete ).map( &:intern )
0
- RULES = %w( before action after always ).map( &:intern )
0
+ RULES = %w( before action after always, handle ).map( &:intern )
0
     
0
     def mappings
0
       @mappings ||= Hash.new { |h,k| h[k] = [] }
0
     end
0
     
0
- def before( options, &block )
0
- end
0
-
0
- def wrap( name, *args, &block )
0
- before( name, *args, &block ) ; after( name, *args, &block )
0
- end
0
-
0
- def after( options, &block )
0
- end
0
-
0
- def always( options, &block )
0
+ def method_missing( name, *args, &block )
0
+ return super unless RULES.include? name
0
+ map( name, args, &block )
0
     end
0
     
0
- def handle( exception )
0
- end
0
-
0
-
0
     def with( options, &block )
0
       @options = options; yield if block_given? ; @options = nil
0
     end
0
 
0
- def path( name, options = {}, &block )
0
- map( options.merge!( :name => name, :target => :path ), &block )
0
+ functor( :map, String, Array, Proc ) { | rule, args, block | map( *( args << block ) ) }
0
+ functor( :map, String, Array ) { | rule, args | mappings[ rule ] << map( *args ) }
0
+ functor( :map, String, Hash, Proc ) do | name, options, block |
0
+ options[:name] = name ; options[:block] = block ; map( options )
0
     end
0
-
0
- def url( name, options = {}, &block )
0
- map( options.merge!( :name => name, :target => :url ), &block )
0
- end
0
-
0
- def map( options, &block )
0
+ functor( :map, String, Hash ) { | name, options | options[:name] = name ; map( options ) }
0
+ functor( :map, Hash ) do | options |
0
       options = ( @options || {} ).merge( options )
0
- options[ :target ] ||= :path
0
       options[ :method ] = method = METHODS.find { |method| options[ method ] }
0
       options[ :pattern ] = options[ method ]
0
- mappings[ :action ].push( Action.new( options, &block ) )
0
+ Action.new( options )
0
     end
0
-
0
+ functor( :map, Exception, String, Hash, Proc ) do | e, name, options, block |
0
+ options[:name] = name ; map( e, options, block )
0
+ end
0
+ functor( :map, Exception, Hash, Proc ) do | e, options, block |
0
+ options[:block] = block ; map( e, options )
0
+ end
0
+ functor( :map, Exception, Hash ) { | options, block | Handler.new( e, options ) }
0
+
0
     def []( request )
0
       returning Hash.new { |h,k| h[k] = [] } do | results |
0
         RULES.each do | rule |
0
@@ -54,6 +48,11 @@ module Waves
0
       end
0
     end
0
 
0
+ private
0
+
0
+ def normalize( options )
0
+ end
0
+
0
   end
0
 
0
 end
0
\ No newline at end of file
...
15
16
17
18
 
19
20
21
...
15
16
17
 
18
19
20
21
0
@@ -15,7 +15,7 @@ module Blog
0
       path( :list, :get => [ :resources ] ) { action( :all ) and render( :list ) }
0
       path( :create, :post => [ :resources ] ) { redirect( paths.read( action( :create ).name, 'edit' ) ) }
0
       path( :read, :get => [ :resource, :name, { :mode => 'show' } ] ) { action( :find, name ) and render( mode ) }
0
- path( :update, :put => [ :resource, :name ] ) { puts "REDIRECT: #{paths.read( name ) }" ; action( :update, name ) and redirect( paths.read( name ) ) }
0
+ path( :update, :put => [ :resource, :name ] ) { action( :update, name ) and redirect( paths.read( name ) ) }
0
       path( :delete, :delete => [ :resource, :name ] ) { action( :delete, name ) }
0
       
0
     end

Comments

    No one has commented yet.