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
Did some refactoring to support multi-app interface. Added new helpers 
that can incorporate the app name: controllers( :blog ). Tweaked the MVC 
layers code. Factored Filebase into a separate gem, taking with it 
attributes.rb.
dyoder (author)
Sun Jul 27 20:38:16 -0700 2008
commit  dfd27af7ba505d8f6485f15b8fd7a38c731b0fbf
tree    94e99796fc143ebd65f06c8c8dea9010c076f399
parent  753bab0c8160035908a950e47f71a1ef1585e039
...
20
21
22
23
 
24
25
26
...
20
21
22
 
23
24
25
26
0
@@ -20,7 +20,7 @@ gem = Gem::Specification.new do |gem|
0
   gem.email = 'dan@zeraweb.com'
0
   gem.platform = Gem::Platform::RUBY
0
   gem.required_ruby_version = '>= 1.8.6'
0
- %w( mongrel rack markaby erubis haml RedCloth metaid
0
+ %w( mongrel rack markaby erubis haml RedCloth metaid filebase
0
       extensions live_console choice daemons rakegen).each do |dep|
0
     gem.add_dependency dep
0
   end
...
127
128
129
130
 
131
132
133
...
127
128
129
 
130
131
132
133
0
@@ -127,7 +127,7 @@ module Waves
0
       #
0
       # to find an instance of a given model. Again, the plurality of the controller and
0
       # model must be the same for this to work.
0
- def model; Waves.application.models[ model_name.intern ]; end
0
+ def model; models[ model_name.intern ]; end
0
       
0
       def attributes; params[model_name.singular.intern]; end
0
       
...
52
53
54
55
 
56
57
58
...
52
53
54
 
55
56
57
58
0
@@ -52,7 +52,7 @@ module Waves
0
       #
0
       def layout( name, assigns = {}, &block )
0
         assigns[ :layout_content ] = capture(&block)
0
- self << Waves.application.views[:layouts].process( request ) do
0
+ self << views[:layouts].process( request ) do
0
           send( name, assigns )
0
         end
0
       end
...
17
18
19
20
 
 
 
21
22
 
23
24
25
...
17
18
19
 
20
21
22
23
 
24
25
26
27
0
@@ -17,9 +17,11 @@ module Waves
0
     # then be called from the template instead of the model helper.
0
     #
0
     module Model
0
-
0
+
0
+ include ResponseMixin
0
+
0
       def model( name )
0
- Waves.application.models[ name ]
0
+ models[ name ]
0
       end
0
       
0
       # Just like model.all. Returns all the instances of that model.
...
11
12
13
 
 
14
15
16
 
17
18
19
...
11
12
13
14
15
16
17
 
18
19
20
21
0
@@ -11,9 +11,11 @@ module Waves
0
     # template.
0
     module View
0
 
0
+ include ResponseMixin
0
+
0
       # Invokes the view for the given model, passing the assigns as instance variables.
0
       def view( model, view, assigns = {} )
0
- self << Waves.application.views[ model ].process( request ) do
0
+ self << views[ model ].process( request ) do
0
           send( view, assigns )
0
         end
0
       end
...
10
11
12
13
 
14
15
16
...
10
11
12
 
13
14
15
16
0
@@ -10,7 +10,7 @@ module Waves
0
           auto_eval :Mapping do
0
             extend Waves::Mapping
0
             handle(Waves::Dispatchers::NotFoundError) do
0
- html = Waves.application.views[:errors].process( request ) do
0
+ html = views[:errors].process( request ) do
0
                 not_found_404( :error => Waves::Dispatchers::NotFoundError )
0
               end
0
               response.status = '404'
...
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
 
29
30
31
...
33
34
35
36
 
 
 
 
 
37
38
39
40
41
42
43
44
45
 
 
 
 
 
46
47
48
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
...
8
9
10
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
12
13
 
14
15
16
17
...
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
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
0
@@ -8,24 +8,10 @@ module Waves
0
 
0
       def self.included( app )
0
         
0
- def app.models ; self::Models ; end
0
- def app.views ; self::Views ; end
0
- def app.controllers ; self::Controllers ; end
0
- def app.helpers ; self::Helpers ; end
0
-
0
- unless ResponseMixin.public_instance_methods.include? 'model'
0
- Waves::ResponseMixin.module_eval do
0
- [ :model, :view, :controller ].each do | k |
0
- functor( k, Object ) { | name | Waves.application.send( k, name.to_s ) }
0
- functor( k, Object, Object ) { | app, name | Waves.applications[ app.to_s ].send( k, name.to_s ) }
0
- end
0
- end
0
- end
0
-
0
         app.auto_create_module( :Models ) do
0
           include AutoCode
0
           auto_create_class :Default
0
- auto_load :Default, :directories => [:models]
0
+ auto_load :Default, :directories => [ :models ]
0
         end
0
         
0
         app.auto_eval( :Models ) do
0
@@ -33,41 +19,60 @@ module Waves
0
           auto_load true, :directories => [ :models ]
0
         end
0
 
0
- app.auto_create_module( :Views ) { include AutoCode }
0
+ app.auto_create_module( :Views ) do
0
+ include AutoCode
0
+ auto_create_class :Default, Waves::Views::Base
0
+ auto_load :Default, :directories => [ :views ]
0
+ end
0
         
0
         app.auto_eval( :Views ) do
0
- auto_create_class :Default, Waves::Views::Base
0
- auto_load :Default, :directories => [:views]
0
           auto_create_class true, app::Views::Default
0
           auto_load true, :directories => [ :views ]
0
         end
0
 
0
- app.auto_create_module( :Controllers ) { include AutoCode }
0
+ app.auto_create_module( :Controllers ) do
0
+ include AutoCode
0
+ auto_create_class :Default, Waves::Controllers::Base
0
+ auto_load :Default, :directories => [ :controllers ]
0
+ end
0
         
0
         app.auto_eval( :Controllers ) do
0
- auto_create_class :Default, Waves::Controllers::Base
0
- auto_load :Default, :directories => [:controllers]
0
           auto_create_class true, app::Controllers::Default
0
           auto_load true, :directories => [ :controllers ]
0
         end
0
 
0
         app.auto_create_module( :Helpers ) do
0
           include AutoCode
0
- auto_create_module { include Waves::Helpers::Default }
0
+ auto_create_module( :Default ) { include Waves::Helpers::Default }
0
+ auto_load :Default, :directories => [ :helpers ]
0
+ auto_create_module( true ) { include app::Helpers::Default }
0
           auto_load true, :directories => [ :helpers ]
0
- end
0
-
0
+ end
0
+
0
         app.auto_eval :Resources do
0
- const_set( :Default, Class.new( Waves::Resources::Base ) ).module_eval do
0
- def controller ; @controller ||= Waves.application.controllers[ singular ].process( @request ) { self } ; end
0
- def view ; @view ||= Waves.application.views[ singular ].process( @request ) { self } ; end
0
+ auto_create_class :Default, Waves::Resources::Base
0
+ auto_load :Default, :directories => [ :resources ]
0
+ auto_eval :Default do
0
+ def controller ; @controller ||= controllers[ singular ].process( @request ) { self } ; end
0
+ def view ; @view ||= views[ singular ].process( @request ) { self } ; end
0
             def action( method, *args ) ; @data = controller.send( method, *args ) ; end
0
             def render( method ) ; view.send( method, ( @data.kind_of?( Enumerable ) ? plural : singular ) => @data ) ; end
0
             def method_missing( name, *args, &block) ; params[ name.to_s ] ; end
0
           end
0
- auto_create_class true, self::Default
0
+ auto_create_class true, app::Resources::Default
0
+ auto_load true, :directories => [ :resources ]
0
         end
0
-
0
+
0
+ lambda {
0
+ string_or_symbol = lambda { |arg| arg.kind_of?(String) || arg.kind_of?(Symbol) }
0
+ Waves::ResponseMixin.module_eval do
0
+ [ :models, :controllers, :views, :helpers ].each do |k|
0
+ functor( k ) { app[ k ] }
0
+ functor( k, string_or_symbol ) { |name| app( name )[ k ] }
0
+ end
0
+ end
0
+ }.call
0
+
0
       end
0
     end
0
   end
...
8
9
10
11
 
12
13
14
...
8
9
10
 
11
12
13
14
0
@@ -8,7 +8,7 @@ module Waves
0
         def self.included(app)
0
           app.module_eval do
0
             auto_eval( :Models ) do
0
- auto_eval( true ) { include Filebase::Model[ :db / self.name.snake_case ] }
0
+ auto_eval( true ) { include ::Filebase::Model[ :db / self.name.snake_case ] }
0
             end
0
           end
0
         end
...
44
45
46
47
 
 
48
49
50
...
44
45
46
 
47
48
49
50
51
0
@@ -44,7 +44,8 @@ module Waves
0
               if @dataset && @dataset.opts[:from] != [ default ]
0
                 # don't clobber dataset from autoloaded file
0
               else
0
- set_dataset Waves.application.database[ basename.snake_case.pluralize.intern ]
0
+
0
+ set_dataset app.database[ basename.snake_case.pluralize.intern ]
0
               end
0
             end
0
           end
...
2
3
4
5
6
 
 
 
 
7
8
9
...
13
14
15
16
 
17
18
19
...
2
3
4
 
 
5
6
7
8
9
10
11
...
15
16
17
 
18
19
20
21
0
@@ -2,8 +2,10 @@ namespace :generate do
0
   
0
     desc 'Generate a Sequel model, with name=<name>'
0
     task :model do |task|
0
- name = ENV['name']
0
- model_name = name.camel_case
0
+
0
+ model_name = ENV['name'].camel_case
0
+ app_name = ( ENV['app'] || Dir.pwd.split('/').last ).camel_case
0
+
0
       raise "Cannot generate Default yet" if model_name == 'Default'
0
 
0
       filename = File.expand_path "models/#{name}.rb"
0
@@ -13,7 +15,7 @@ namespace :generate do
0
       end
0
 
0
       model = <<TEXT
0
-module #{Waves.application.name}
0
+module #{app_name}
0
   module Models
0
     class #{model_name} < Default
0
 
...
10
11
12
13
 
 
 
14
15
16
...
10
11
12
 
13
14
15
16
17
18
0
@@ -10,7 +10,9 @@ namespace :schema do
0
   desc "Performs Sequel migrations to version=<version>"
0
   task :migrate do |task|
0
     version = ENV['version']; version = version.to_i unless version.nil?
0
- Sequel::Migrator.apply( Waves.application.database, Waves::Layers::ORM.migration_directory , version )
0
+ app_name = ( ENV['app'] || Dir.pwd.split('/').last ).camel_case
0
+
0
+ Sequel::Migrator.apply( Waves.applications[ app_name.to_sym ].database, Waves::Layers::ORM.migration_directory , version )
0
   end
0
 
0
 end
...
16
17
18
19
20
21
22
...
16
17
18
 
19
20
21
0
@@ -16,7 +16,6 @@ module Waves
0
 
0
         def app.config ; Waves.config ; end
0
         def app.configurations ; self::Configurations ; end
0
- def app.paths ; configurations::Mapping.named; end
0
         def app.resources ; self::Resources ; end
0
         
0
         app.instance_eval { include AutoCode }
...
11
12
13
14
 
15
16
17
...
11
12
13
 
14
15
16
17
0
@@ -11,7 +11,7 @@ module Waves
0
       def initialize( options ) ; @pattern = options[ :path ] ; end
0
       
0
       functor( :match, Waves::Request ) { | request | match( @pattern, request.path ) }
0
- functor( :match, nil, String ) { |pattern, path| {} }
0
+ functor( :match, nil, String ) { |pattern, path| nil }
0
       functor( :match, [], '/' ) { | pattern, path | {} }
0
       functor( :match, Array, String ) { | pattern, path | match( pattern, path.split('/')[1..-1] ) }
0
       functor( :match, Array, nil ) { | pattern, path | nil }
...
36
37
38
39
40
 
41
42
43
...
36
37
38
 
 
39
40
41
42
0
@@ -36,8 +36,7 @@ module Waves
0
           end
0
 
0
           def helper( path )
0
- Waves.application.helpers[
0
- File.basename( File.dirname( path ) ).camel_case ]
0
+ Waves.application[ :helpers ][ File.basename( File.dirname( path ) ).camel_case ]
0
           end
0
         end
0
       end
...
7
8
9
 
10
11
12
...
23
24
25
26
 
27
28
29
...
7
8
9
10
11
12
13
...
24
25
26
 
27
28
29
30
0
@@ -7,6 +7,7 @@ module Waves
0
       attr_reader :request
0
 
0
       include ResponseMixin
0
+ include Functor::Method
0
       
0
       def self.included( target )
0
         parent = target.superclass
0
@@ -23,7 +24,7 @@ module Waves
0
       def singular ; self.class.singular ; end
0
       def plural ; self.class.plural ; end
0
       def redirect( path ) ; request.redirect( path ) ; end
0
- def paths ; self.class.paths ; end
0
+ functor( :paths ) { self.class.paths }
0
       
0
     end
0
       
...
5
6
7
8
9
10
 
 
11
12
13
...
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
...
5
6
7
 
 
 
8
9
10
11
12
...
21
22
23
 
 
 
 
 
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
0
@@ -5,9 +5,8 @@ module Waves
0
   # objects, but which may still be useful for constructing a response.
0
   #
0
   # This mixin assumes that a @request@ accessor already exists.
0
- module ResponseMixin
0
- include Functor::Method
0
-
0
+ module ResponseMixin
0
+ include Functor::Method
0
     # Access the response.
0
     def response; request.response; end
0
     # Access the request parameters.
0
@@ -22,17 +21,24 @@ module Waves
0
     def domain; request.domain; end
0
     # Issue a redirect for the given location.
0
     def redirect(location, status = '302'); request.redirect(location, status); end
0
- # access stuff from an app
0
- functor( :mapping ) { Waves.application.mapping }
0
- functor( :mapping, Object ) { | app | Waves.applications[ app.to_s ].mapping }
0
- functor( :resource, Object, Object ) { | app, name | Waves.applications[ app.to_s ].resources[ name.to_s ] }
0
- functor( :resource, Object ) { | name | Waves.application.resources[ name.to_s ] }
0
     # Raise a "not found" exception.
0
     def not_found; request.not_found; end
0
     # Access the Waves::Logger.
0
     def log; Waves::Logger; end
0
     # Access the Blackboard
0
     def blackboard; request.blackboard; end
0
+ # access stuff from an app
0
+ def app_name ; self.name.split('::').first.snake_case.to_sym ; end
0
+
0
+ lambda {
0
+ string_or_symbol = lambda { |arg| arg.kind_of?(String) || arg.kind_of?(Symbol) }
0
+ functor( :app ) { app( app_name ) }
0
+ functor( :app, string_or_symbol ) { |name| Waves.applications[ name ] }
0
+ functor( :resources ) { app[ :resources ] }
0
+ functor( :resources, string_or_symbol ) { |name| app( name )[ :resources ] }
0
+ functor( :paths, string_or_symbol ) { |rname| resources[ rname ].paths }
0
+ functor( :paths, string_or_symbol, string_or_symbol ) { |aname, rname| resources( aname )[ rname ].paths }
0
+ }.call
0
 
0
   end
0
 
...
4
5
6
 
 
7
8
9
...
13
14
15
16
 
17
18
19
...
29
30
31
 
 
32
33
34
...
38
39
40
41
 
42
43
44
...
54
55
56
 
 
57
58
59
...
63
64
65
66
 
67
68
69
...
4
5
6
7
8
9
10
11
...
15
16
17
 
18
19
20
21
...
31
32
33
34
35
36
37
38
...
42
43
44
 
45
46
47
48
...
58
59
60
61
62
63
64
65
...
69
70
71
 
72
73
74
75
0
@@ -4,6 +4,8 @@ namespace :generate do
0
   task :controller do |task|
0
     name = ENV['name']
0
     controller_name = name.camel_case
0
+ app_name = ( ENV['app'] || Dir.pwd.split('/').last ).camel_case
0
+
0
     raise "Cannot generate Default yet" if controller_name == 'Default'
0
     
0
     filename = File.expand_path "controllers/#{name}.rb"
0
@@ -13,7 +15,7 @@ namespace :generate do
0
     end
0
 
0
     controller = <<TEXT
0
-module #{Waves.application.name}
0
+module #{app_name}
0
   module Controllers
0
     class #{controller_name} < Default
0
 
0
@@ -29,6 +31,8 @@ TEXT
0
   task :view do |task|
0
     name = ENV['name']
0
     view_name = name.camel_case
0
+ app_name = ( ENV['app'] || Dir.pwd.split('/').last ).camel_case
0
+
0
     raise "Cannot generate Default yet" if view_name == 'Default'
0
     
0
     filename = File.expand_path "views/#{name}.rb"
0
@@ -38,7 +42,7 @@ TEXT
0
     end
0
 
0
     view = <<TEXT
0
-module #{Waves.application.name}
0
+module #{app_name}
0
   module Views
0
     class #{view_name} < Default
0
 
0
@@ -54,6 +58,8 @@ TEXT
0
   task :helper do |task|
0
     name = ENV['name']
0
     helper_name = name.camel_case
0
+ app_name = ( ENV['app'] || Dir.pwd.split('/').last ).camel_case
0
+
0
     raise "Cannot generate Default yet" if helper_name == 'Default'
0
     
0
     filename = File.expand_path "helpers/#{name}.rb"
0
@@ -63,7 +69,7 @@ TEXT
0
     end
0
     
0
     helper = <<TEXT
0
-module #{Waves.application.name}
0
+module #{app_name}
0
   module Helpers
0
     module #{helper_name}
0
       include Waves::Helpers::Default
...
9
10
11
12
13
14
15
...
25
26
27
 
 
 
28
29
30
...
34
35
36
37
38
39
40
...
9
10
11
 
12
13
14
...
24
25
26
27
28
29
30
31
32
...
36
37
38
 
39
40
41
0
@@ -9,7 +9,6 @@ require 'daemons'
0
 require 'live_console'
0
 
0
 require 'autocode'
0
-gem 'dyoder-functor'
0
 require 'functor'
0
 
0
 # for mimetypes only or when using as default handler
0
@@ -25,6 +24,9 @@ require 'benchmark'
0
 # require 'memcache'
0
 require 'base64'
0
 
0
+require 'filebase'
0
+require 'filebase/model'
0
+
0
 # selected project-specific extensions
0
 require 'utilities/module'
0
 require 'utilities/string'
0
@@ -34,7 +36,6 @@ require 'utilities/integer'
0
 require 'utilities/inflect'
0
 require 'utilities/proc'
0
 require 'utilities/hash'
0
-require 'utilities/attributes'
0
 require 'utilities/tempfile'
0
 # waves Runtime
0
 require 'dispatchers/base'

Comments

    No one has commented yet.