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
moved ORM controller helpers into modules
automatthew (author)
Mon Jun 30 11:15:26 -0700 2008
commit  d564345c09dce90c8feedb7ef138117cbde3c746
tree    eb48815f8f7ec937975a3637319b4900173d6fc1
parent  91bf517cba0b0374adf2267a3d87865a1d1be126
...
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
...
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
 
 
 
 
 
 
 
 
 
 
84
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
88
89
...
13
14
15
16
17
18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
...
54
55
56
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
0
@@ -13,25 +13,21 @@ module Waves
0
   module Layers
0
     module ORM
0
 
0
+ # Sets up the ActiveRecord connection and configures AutoCode on Models, so that constants in that
0
+ # namespace get loaded from file or created as subclasses of Models::Default
0
       module ActiveRecord
0
-
0
- # def active_record
0
- # unless @active_record
0
- # ::ActiveRecord::Base.establish_connection(config.database)
0
- # @active_record = ::ActiveRecord::Base.connection
0
- # end
0
- # @active_record
0
- # end
0
-
0
- # def database
0
- # @database ||= active_record
0
- # end
0
-
0
- def model_config(context, name)
0
- active_record
0
- context.set_table_name(name)
0
- end
0
         
0
+ # On inclusion, this module:
0
+ # - creates on the application module a database method that establishes and returns the ActiveRecord connection
0
+ # - arranges for autoloading/autocreation of missing constants in the Models namespace
0
+ # - defines ActiveRecord-specific helper methods on Waves::Controllers::Base
0
+ #
0
+ # The controller helper methdods are:
0
+ # - all
0
+ # - find(name)
0
+ # - create
0
+ # - delete(name)
0
+ # - update(name)
0
         
0
         def self.included(app)
0
           
0
@@ -58,32 +54,38 @@ module Waves
0
               set_table_name basename.snake_case.pluralize.intern
0
             end
0
           end
0
-
0
- Waves::Controllers::Base.module_eval do
0
- def all #:nodoc:
0
- model.find(:all)
0
- end
0
-
0
- def find( id ) #:nodoc:
0
- model.find(id) or not_found
0
- end
0
-
0
- def create #:nodoc:
0
- model.create( attributes )
0
- end
0
-
0
- def delete( id ) #:nodoc:
0
- find( id ).destroy
0
- end
0
-
0
- def update( id ) #:nodoc:
0
- instance = find( id )
0
- instance.update_attributes( attributes )
0
- instance
0
- end
0
+
0
+ Waves::Controllers::Base.instance_eval do
0
+ include Waves::Layers::ORM::ActiveRecord::ControllerMethods
0
+ end
0
+
0
+ end
0
+
0
+ # Mixed into Waves::Controllers::Base. Provides ORM-specific helper methods for model access.
0
+ module ControllerMethods
0
+ def all
0
+ model.find(:all)
0
           end
0
           
0
+ def find( id )
0
+ model.find(id) or not_found
0
+ end
0
+
0
+ def create
0
+ model.create( attributes )
0
+ end
0
+
0
+ def delete( id )
0
+ find( id ).destroy
0
+ end
0
+
0
+ def update( id )
0
+ instance = find( id )
0
+ instance.update_attributes( attributes )
0
+ instance
0
+ end
0
         end
0
+
0
       end
0
     end
0
   end
...
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
 
74
75
76
77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
79
80
...
49
50
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
53
54
55
56
 
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
0
@@ -49,32 +49,38 @@ module Waves
0
             end
0
           end
0
             
0
- Waves::Controllers::Base.module_eval do
0
- def all #:nodoc:
0
- model.all
0
- end
0
-
0
- def find( name ) #:nodoc:
0
- model[ :name => name ] or not_found
0
- end
0
-
0
- def create #:nodoc:
0
- model.create( attributes )
0
- end
0
-
0
- def delete( name ) #:nodoc:
0
- find( name ).destroy
0
- end
0
-
0
- def update( name ) #:nodoc:
0
- instance = find( name )
0
- instance.update_with_params( attributes )
0
- instance
0
- end
0
+ Waves::Controllers::Base.instance_eval do
0
+ include Waves::Layers::ORM::Sequel::ControllerMethods
0
           end
0
             
0
         end
0
- end
0
+
0
+ # Mixed into Waves::Controllers::Base. Provides ORM-specific helper methods for model access.
0
+ module ControllerMethods
0
+ def all
0
+ model.all
0
+ end
0
+
0
+ def find( name )
0
+ model[ :name => name ] or not_found
0
+ end
0
+
0
+ def create
0
+ model.create( attributes )
0
+ end
0
+
0
+ def delete( name )
0
+ find( name ).destroy
0
+ end
0
+
0
+ def update( name )
0
+ instance = find( name )
0
+ instance.update_with_params( attributes )
0
+ instance
0
+ end
0
+ end
0
+
0
+ end
0
     end
0
   end
0
 end

Comments

    No one has commented yet.