waves 0.8.2 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/waves +4 -3
- data/doc/VERSION +1 -1
- data/lib/waves.rb +52 -40
- data/lib/{caches → waves/caches}/file.rb +3 -1
- data/lib/waves/caches/memcached.rb +56 -0
- data/lib/{caches → waves/caches}/simple.rb +6 -7
- data/lib/{caches → waves/caches}/synchronized.rb +15 -1
- data/lib/{commands → waves/commands}/console.rb +4 -4
- data/lib/{commands → waves/commands}/generate.rb +6 -5
- data/lib/{commands → waves/commands}/help.rb +0 -0
- data/lib/{commands → waves/commands}/server.rb +1 -1
- data/lib/{dispatchers → waves/dispatchers}/base.rb +17 -31
- data/lib/waves/dispatchers/default.rb +19 -0
- data/lib/{ext → waves/ext}/float.rb +0 -0
- data/lib/{ext → waves/ext}/hash.rb +0 -0
- data/lib/{ext → waves/ext}/integer.rb +16 -1
- data/lib/{ext → waves/ext}/kernel.rb +3 -7
- data/lib/{ext → waves/ext}/module.rb +3 -3
- data/lib/{ext → waves/ext}/object.rb +2 -0
- data/lib/waves/ext/string.rb +73 -0
- data/lib/{ext → waves/ext}/symbol.rb +0 -1
- data/lib/{ext → waves/ext}/tempfile.rb +0 -0
- data/lib/waves/ext/time.rb +5 -0
- data/lib/{foundations → waves/foundations}/classic.rb +9 -21
- data/lib/{foundations → waves/foundations}/compact.rb +15 -20
- data/lib/waves/foundations/rest.rb +311 -0
- data/lib/waves/helpers/basic.rb +13 -0
- data/lib/{helpers → waves/helpers}/doc_type.rb +3 -0
- data/lib/waves/helpers/form.rb +94 -0
- data/lib/waves/helpers/formatting.rb +14 -0
- data/lib/waves/layers/mvc.rb +65 -0
- data/lib/{layers → waves/layers}/mvc/controllers.rb +0 -0
- data/lib/{layers → waves/layers}/mvc/extensions.rb +23 -11
- data/lib/{layers → waves/layers}/orm/migration.rb +0 -0
- data/lib/{layers → waves/layers}/orm/providers/active_record.rb +2 -5
- data/lib/{layers → waves/layers}/orm/providers/active_record/migrations/empty.rb.erb +0 -0
- data/lib/{layers → waves/layers}/orm/providers/active_record/tasks/generate.rb +1 -1
- data/lib/{layers → waves/layers}/orm/providers/active_record/tasks/schema.rb +1 -1
- data/lib/{layers → waves/layers}/orm/providers/data_mapper.rb +0 -0
- data/lib/{layers → waves/layers}/orm/providers/filebase.rb +0 -0
- data/lib/{layers → waves/layers}/orm/providers/sequel.rb +28 -29
- data/lib/{layers → waves/layers}/orm/providers/sequel/migrations/empty.rb.erb +0 -0
- data/lib/{layers → waves/layers}/orm/providers/sequel/tasks/generate.rb +1 -1
- data/lib/{layers → waves/layers}/orm/providers/sequel/tasks/schema.rb +2 -0
- data/lib/waves/layers/rack/rack_cache.rb +32 -0
- data/lib/waves/layers/renderers/erubis.rb +52 -0
- data/lib/waves/layers/renderers/haml.rb +67 -0
- data/lib/waves/layers/renderers/markaby.rb +41 -0
- data/lib/waves/layers/text/inflect/english.rb +42 -0
- data/lib/waves/matchers/accept.rb +47 -0
- data/lib/waves/matchers/ext.rb +27 -0
- data/lib/waves/matchers/path.rb +72 -0
- data/lib/waves/matchers/query.rb +43 -0
- data/lib/waves/matchers/request.rb +86 -0
- data/lib/waves/matchers/requested.rb +31 -0
- data/lib/{matchers → waves/matchers}/resource.rb +8 -1
- data/lib/waves/matchers/traits.rb +30 -0
- data/lib/waves/matchers/uri.rb +69 -0
- data/lib/waves/media/mime_types.rb +542 -0
- data/lib/waves/renderers/mixin.rb +9 -0
- data/lib/waves/request/accept.rb +92 -0
- data/lib/{runtime → waves/request}/request.rb +77 -61
- data/lib/waves/resources/file_mixin.rb +11 -0
- data/lib/{resources → waves/resources}/mixin.rb +42 -44
- data/lib/waves/resources/paths.rb +132 -0
- data/lib/waves/response/client_errors.rb +10 -0
- data/lib/waves/response/packaged.rb +19 -0
- data/lib/waves/response/redirects.rb +35 -0
- data/lib/{runtime → waves/response}/response.rb +29 -11
- data/lib/{runtime → waves/response}/response_mixin.rb +30 -17
- data/lib/waves/runtime/applications.rb +18 -0
- data/lib/{runtime → waves/runtime}/configuration.rb +31 -25
- data/lib/waves/runtime/console.rb +24 -0
- data/lib/{runtime → waves/runtime}/logger.rb +3 -3
- data/lib/{runtime → waves/runtime}/mocks.rb +2 -2
- data/lib/waves/runtime/rackup.rb +37 -0
- data/lib/waves/runtime/runtime.rb +48 -0
- data/lib/waves/runtime/server.rb +33 -0
- data/lib/{servers → waves/servers}/base.rb +0 -0
- data/lib/{servers → waves/servers}/mongrel.rb +0 -0
- data/lib/{servers → waves/servers}/webrick.rb +0 -0
- data/lib/{tasks → waves/tasks}/gem.rb +0 -0
- data/lib/{tasks → waves/tasks}/generate.rb +0 -0
- data/lib/waves/views/cassy.rb +173 -0
- data/lib/{views → waves/views}/errors.rb +8 -7
- data/lib/waves/views/mixin.rb +23 -0
- data/lib/waves/views/templated.rb +40 -0
- data/samples/basic/basic_startup.rb +70 -0
- data/samples/basic/config.ru +9 -0
- data/samples/blog/configurations/development.rb +17 -16
- data/samples/blog/configurations/production.rb +0 -11
- data/samples/blog/resources/entry.rb +3 -3
- data/samples/blog/resources/map.rb +10 -3
- data/samples/blog/startup.rb +4 -3
- data/templates/classic/Rakefile +28 -29
- data/templates/classic/configurations/default.rb.erb +8 -3
- data/templates/classic/configurations/development.rb.erb +1 -20
- data/templates/classic/configurations/production.rb.erb +2 -16
- data/templates/classic/public/images/favicon.ico +0 -0
- data/templates/classic/resources/server.rb.erb +9 -0
- data/templates/classic/startup.rb.erb +3 -3
- data/templates/classic/views/css.rb.erb +14 -0
- data/templates/classic/views/default.rb.erb +17 -0
- data/templates/classic/views/errors.rb.erb +10 -0
- data/templates/classic/views/pages.rb.erb +14 -0
- data/templates/compact/startup.rb.erb +8 -3
- data/test/ext/object.rb +55 -0
- data/test/ext/shortcuts.rb +73 -0
- data/test/helpers.rb +17 -0
- data/test/match/accept.rb +78 -0
- data/test/match/ext.rb +156 -0
- data/test/match/methods.rb +22 -0
- data/test/match/params.rb +33 -0
- data/test/match/path.rb +106 -0
- data/test/match/query.rb +60 -0
- data/test/match/request.rb +91 -0
- data/test/match/requested.rb +149 -0
- data/test/match/uri.rb +136 -0
- data/test/process/request.rb +75 -0
- data/test/process/resource.rb +53 -0
- data/test/resources/path.rb +166 -0
- data/test/runtime/configurations.rb +19 -0
- data/test/runtime/request.rb +63 -0
- data/test/runtime/response.rb +85 -0
- data/test/views/views.rb +40 -0
- metadata +243 -157
- data/lib/caches/memcached.rb +0 -40
- data/lib/dispatchers/default.rb +0 -25
- data/lib/ext/string.rb +0 -20
- data/lib/helpers/basic.rb +0 -11
- data/lib/helpers/extended.rb +0 -21
- data/lib/helpers/form.rb +0 -42
- data/lib/helpers/formatting.rb +0 -30
- data/lib/helpers/layouts.rb +0 -37
- data/lib/helpers/model.rb +0 -37
- data/lib/helpers/view.rb +0 -22
- data/lib/layers/inflect/english.rb +0 -67
- data/lib/layers/mvc.rb +0 -54
- data/lib/layers/renderers/erubis.rb +0 -60
- data/lib/layers/renderers/haml.rb +0 -47
- data/lib/layers/renderers/markaby.rb +0 -29
- data/lib/matchers/accept.rb +0 -21
- data/lib/matchers/base.rb +0 -30
- data/lib/matchers/content_type.rb +0 -17
- data/lib/matchers/path.rb +0 -67
- data/lib/matchers/query.rb +0 -21
- data/lib/matchers/request.rb +0 -27
- data/lib/matchers/traits.rb +0 -19
- data/lib/matchers/uri.rb +0 -20
- data/lib/renderers/mixin.rb +0 -36
- data/lib/resources/paths.rb +0 -34
- data/lib/runtime/console.rb +0 -23
- data/lib/runtime/mime_types.rb +0 -536
- data/lib/runtime/monitor.rb +0 -32
- data/lib/runtime/runtime.rb +0 -67
- data/lib/runtime/server.rb +0 -20
- data/lib/runtime/session.rb +0 -27
- data/lib/runtime/worker.rb +0 -86
- data/lib/views/mixin.rb +0 -62
- data/samples/blog/blog.db +0 -0
- data/samples/blog/log/waves.production +0 -3
- data/templates/classic/resources/map.rb.erb +0 -8
- data/templates/classic/templates/errors/not_found_404.mab +0 -7
- data/templates/classic/templates/errors/server_error_500.mab +0 -7
- data/templates/classic/templates/layouts/default.mab +0 -14
- data/templates/classic/tmp/sessions/.gitignore +0 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
module Basic
|
4
|
+
|
5
|
+
# Escape a string as HTML content.
|
6
|
+
def escape_html(s); Rack::Utils.escape_html(s); end
|
7
|
+
|
8
|
+
# Escape a URI, converting quotes and spaces and so on.
|
9
|
+
def escape_uri(s); Rack::Utils.escape(s); end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -27,6 +27,9 @@ module Waves
|
|
27
27
|
:xhtml2 => "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
|
28
28
|
}
|
29
29
|
|
30
|
+
# Allows you to generate a doctype declaration. Note that if you'll only
|
31
|
+
# need this helper if you're not using Hoshi, since Hoshi already provides
|
32
|
+
# this built-in.
|
30
33
|
def doctype(type) ; self << DOCTYPES[type||:html4_strict] ; end
|
31
34
|
|
32
35
|
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
# Form helpers are used in generating forms. Since Hoshi already provides Ruby
|
6
|
+
# methods for basic form generation, the focus of this helper is on providing methods
|
7
|
+
# to handle things that go beyond the basics.
|
8
|
+
#
|
9
|
+
# Example:
|
10
|
+
#
|
11
|
+
# editor( @blog.entry, :heading => 'Edit Blog Entry', :method => :put) {
|
12
|
+
# property @blog.entry, :name => :title, :type => :text
|
13
|
+
# property @blog.entry, :name => :content, :type => :text, :size => large
|
14
|
+
# property @blog.entry, :name => :published?, :type => :boolean
|
15
|
+
# }
|
16
|
+
#
|
17
|
+
|
18
|
+
module Form
|
19
|
+
|
20
|
+
def editor( instance, options = {})
|
21
|
+
options = { :method => :put, :buttons => true,
|
22
|
+
:heading => instance.class.name.in_words.title_case }.merge( options )
|
23
|
+
h1 options[:heading] if options[:heading]
|
24
|
+
form( :method => :post, :action => paths.put( instance.key ) ) {
|
25
|
+
input( :type => :hidden, :name => :_method, :value => :put ) if options[:method] == :put
|
26
|
+
div.properties { yield }
|
27
|
+
p( :class => 'button panel' ) { submit; cancel } if options[:buttons]
|
28
|
+
}
|
29
|
+
end
|
30
|
+
|
31
|
+
def properties(&block)
|
32
|
+
fieldset do
|
33
|
+
yield
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def property( instance, options )
|
38
|
+
div( :class => "property #{options[:type]} #{options[:size]}") {
|
39
|
+
label options[:name].capitalize
|
40
|
+
div( :class => 'control' ) { self.send( "#{options[:type]}_field", instance, options ) }
|
41
|
+
}
|
42
|
+
end
|
43
|
+
|
44
|
+
def text_field( instance, options )
|
45
|
+
if options[:size] == :large
|
46
|
+
textarea( instance.send( options[:name] ),
|
47
|
+
:name => "#{instance.class.basename.snake_case}.#{options[:name]}" )
|
48
|
+
else
|
49
|
+
input( :name => "#{instance.class.basename.snake_case}.#{options[:name]}",
|
50
|
+
:type => :text, :value => instance.send( options[:name] ) )
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def integer_field( instance, options )
|
55
|
+
input( :name => "#{instance.class.basename.snake_case}.#{options[:name]}",
|
56
|
+
:type => :text, :value => instance.send( options[:name] ) )
|
57
|
+
end
|
58
|
+
|
59
|
+
def float_field( instance, options )
|
60
|
+
input( :name => "#{instance.class.basename.snake_case}.#{options[:name]}",
|
61
|
+
:type => :text, :value => instance.send( options[:name] ) )
|
62
|
+
end
|
63
|
+
|
64
|
+
def boolean_field( instance, options )
|
65
|
+
on = instance.send( options[:name] )
|
66
|
+
radio_button( 'Yes', "#{instance.class.basename.snake_case}.#{options[:name]}", 't', on )
|
67
|
+
radio_button( 'No', "#{instance.class.basename.snake_case}.#{options[:name]}", 'f', !on )
|
68
|
+
end
|
69
|
+
|
70
|
+
def radio_button( label, name, value, on )
|
71
|
+
# can't use hoshi input method here thx 2 checked
|
72
|
+
span label
|
73
|
+
raw( "<input type='radio' name='#{name}' \
|
74
|
+
value='#{value}' #{'checked' if on}/>" )
|
75
|
+
end
|
76
|
+
|
77
|
+
def file_field( instance, options )
|
78
|
+
input( :type => :file, :name => "#{instance.class.basename.snake_case}.#{options[:name]}" )
|
79
|
+
end
|
80
|
+
|
81
|
+
def submit( label = "Save")
|
82
|
+
input :type => :submit, :value => label
|
83
|
+
end
|
84
|
+
|
85
|
+
def cancel( label = "Cancel" )
|
86
|
+
a label, :href => 'javascript:window.history.back()'
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
module MVC
|
4
|
+
|
5
|
+
def self.included( app )
|
6
|
+
|
7
|
+
require 'waves/layers/mvc/extensions'
|
8
|
+
require 'waves/layers/mvc/controllers'
|
9
|
+
require 'hoshi'
|
10
|
+
require 'waves/helpers/basic'
|
11
|
+
require 'waves/helpers/formatting'
|
12
|
+
require 'waves/helpers/form'
|
13
|
+
|
14
|
+
app.auto_create_module( :Models ) do
|
15
|
+
auto_create_class :Default
|
16
|
+
auto_load :Default, :directories => [ :models ]
|
17
|
+
auto_create_class true, :Default
|
18
|
+
auto_load true, :directories => [ :models ]
|
19
|
+
end
|
20
|
+
|
21
|
+
app.auto_create_module( :Views ) do
|
22
|
+
auto_create_class :Default, Hoshi::View[:html4] do
|
23
|
+
include Waves::Views::Mixin
|
24
|
+
include Waves::Helpers::Basic
|
25
|
+
include Waves::Helpers::Formatting
|
26
|
+
include Waves::Helpers::Form
|
27
|
+
end
|
28
|
+
auto_create_class :Templated do
|
29
|
+
include Waves::Views::Mixin
|
30
|
+
include Waves::Views::Templated
|
31
|
+
end
|
32
|
+
auto_load :Default, :directories => [ :views ]
|
33
|
+
auto_create_class true, :Default
|
34
|
+
auto_load true, :directories => [ :views ]
|
35
|
+
end
|
36
|
+
|
37
|
+
app.auto_create_module( :Controllers ) do
|
38
|
+
auto_create_class :Default, Waves::Controllers::Base
|
39
|
+
auto_load :Default, :directories => [ :controllers ]
|
40
|
+
auto_create_class true, :Default
|
41
|
+
auto_load true, :directories => [ :controllers ]
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# We autoload helpers and so forth to emulate Rails technique
|
46
|
+
# of having an application-level helper (Default) and then one
|
47
|
+
# per view class. However, we only use this with templated views
|
48
|
+
# (since mixing in a helper module is sometimes a bit tricky).
|
49
|
+
# "Native" Waves views (aka Hoshi) are ordinary classes so they
|
50
|
+
# don't really need this, but you can always just include a class
|
51
|
+
# level helper and it will automatically pick up your defaults
|
52
|
+
# if it is not explicitly defined.
|
53
|
+
#
|
54
|
+
|
55
|
+
app.auto_create_module( :Helpers ) do
|
56
|
+
auto_create_module( :Default )
|
57
|
+
auto_load :Default, :directories => [ :helpers ]
|
58
|
+
auto_create_module( true ) { include app::Helpers::Default }
|
59
|
+
auto_load true, :directories => [ :helpers ]
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
File without changes
|
@@ -4,16 +4,6 @@ module Waves
|
|
4
4
|
|
5
5
|
module Mixin
|
6
6
|
|
7
|
-
def controller( resource = nil )
|
8
|
-
resource ||= self.class.basename
|
9
|
-
@controller ||= app::Controllers[ resource ].new( @request )
|
10
|
-
end
|
11
|
-
|
12
|
-
def view( resource = nil )
|
13
|
-
resource ||= self.class.basename
|
14
|
-
@view ||= app::Views[ resource ].new( @request )
|
15
|
-
end
|
16
|
-
|
17
7
|
end
|
18
8
|
|
19
9
|
end
|
@@ -32,7 +22,22 @@ module Waves
|
|
32
22
|
#
|
33
23
|
# to find an instance of a given model. Again, the plurality of the controller and
|
34
24
|
# model must be the same for this to work.
|
35
|
-
def model
|
25
|
+
def model( resource = nil )
|
26
|
+
resource ||= self.class.basename.snake_case
|
27
|
+
app::Models[ resource ]
|
28
|
+
end
|
29
|
+
|
30
|
+
def controller( resource = nil )
|
31
|
+
resource ||= self.class.basename.snake_case
|
32
|
+
@controller ||= {}
|
33
|
+
@controller[resource] ||= app::Controllers[ resource ].new( @request )
|
34
|
+
end
|
35
|
+
|
36
|
+
def view( resource = nil )
|
37
|
+
resource ||= self.class.basename.snake_case
|
38
|
+
@view ||= {}
|
39
|
+
@view[resource] ||= app::Views[ resource ].new( @request )
|
40
|
+
end
|
36
41
|
|
37
42
|
# MVC Params get automatically destructured with the keys as accessors methods.
|
38
43
|
# You can still access the original query by calling request.query
|
@@ -40,6 +45,13 @@ module Waves
|
|
40
45
|
@query ||= Waves::Request::Query.new(
|
41
46
|
Waves::Request::Utilities.destructure( request.query ) )
|
42
47
|
end
|
48
|
+
|
49
|
+
# Both the query and capture merged together
|
50
|
+
def params
|
51
|
+
@params ||= Waves::Request::Query.new( captured ?
|
52
|
+
Waves::Request::Utilities.destructure( request.query ).merge( captured.to_h ) :
|
53
|
+
Waves::Request::Utilities.destructure( request.query ) )
|
54
|
+
end
|
43
55
|
|
44
56
|
# Attributes are just the query elements specific to the model associated with
|
45
57
|
# the current resource.
|
File without changes
|
@@ -34,18 +34,15 @@ module Waves
|
|
34
34
|
end
|
35
35
|
|
36
36
|
app.auto_create_module( :Models ) do
|
37
|
-
include AutoCode
|
38
37
|
auto_create_class :Default, ::ActiveRecord::Base
|
39
38
|
auto_load :Default, :directories => [ :models ]
|
40
|
-
end
|
41
|
-
|
42
|
-
app.auto_eval :Models do
|
43
39
|
auto_create_class true, app::Models::Default
|
44
40
|
auto_load true, :directories => [ :models ]
|
45
41
|
|
46
42
|
auto_eval true do
|
43
|
+
next if self.basename == "Default"
|
47
44
|
app.database
|
48
|
-
set_table_name basename.snake_case.pluralize.intern
|
45
|
+
set_table_name self.basename.snake_case.pluralize.intern
|
49
46
|
end
|
50
47
|
end
|
51
48
|
|
File without changes
|
@@ -6,7 +6,7 @@ namespace :generate do
|
|
6
6
|
model_name = name.camel_case
|
7
7
|
raise "Cannot generate Default yet" if model_name == 'Default'
|
8
8
|
|
9
|
-
filename = File.expand_path "models/#{
|
9
|
+
filename = File.expand_path "models/#{model_name}.rb"
|
10
10
|
if File.exist?(filename)
|
11
11
|
$stderr.puts "#{filename} already exists"
|
12
12
|
exit
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Waves
|
2
2
|
module Layers
|
3
3
|
module ORM # :nodoc:
|
4
|
-
|
4
|
+
|
5
5
|
# The Sequel ORM layer sets up the Sequel connection and configures AutoCode on Models, so that constants in that
|
6
6
|
# namespace get loaded from file or created as subclasses of Models::Default. The dataset for models is set to the
|
7
7
|
# snakecased version of the model's class name.
|
@@ -10,7 +10,7 @@ module Waves
|
|
10
10
|
# - creates on the application module a database method that establishes the Sequel connection
|
11
11
|
# - arranges for autoloading/autocreation of missing constants in the Models namespace
|
12
12
|
# - defines Sequel-specific helper methods on Waves::Controllers::Base
|
13
|
-
#
|
13
|
+
#
|
14
14
|
# The controller helper methdods are:
|
15
15
|
# - all
|
16
16
|
# - find(name)
|
@@ -18,45 +18,43 @@ module Waves
|
|
18
18
|
# - delete(name)
|
19
19
|
# - update(name)
|
20
20
|
#
|
21
|
-
|
22
|
-
|
21
|
+
|
22
|
+
|
23
23
|
def self.included(app)
|
24
|
-
|
25
24
|
gem 'sequel', '>= 2.0.0'
|
26
25
|
require 'sequel'
|
27
26
|
require "#{File.dirname(__FILE__)}/sequel/tasks/schema" if defined?(Rake)
|
28
27
|
require "#{File.dirname(__FILE__)}/sequel/tasks/generate" if defined?(Rake)
|
29
|
-
|
30
|
-
def app.database ; @sequel ||= ::Sequel.
|
31
|
-
|
28
|
+
|
29
|
+
def app.database ; @sequel ||= ::Sequel.connect( Waves.config.database ) ; end
|
30
|
+
|
31
|
+
app.database.loggers << Waves.log
|
32
|
+
|
32
33
|
app.auto_create_module( :Models ) do
|
33
|
-
include AutoCode
|
34
34
|
auto_create_class :Default, ::Sequel::Model
|
35
35
|
auto_load :Default, :directories => [ :models ]
|
36
|
-
|
37
|
-
|
38
|
-
app.auto_eval :Models do
|
39
|
-
auto_create_class true, app::Models::Default
|
36
|
+
auto_create_class true, :Default
|
40
37
|
auto_load true, :directories => [ :models ]
|
38
|
+
|
41
39
|
# set the Sequel dataset based on the model class name
|
42
|
-
# note that this is not done for app::Models::Default, as it isn't
|
40
|
+
# note that this is not done for app::Models::Default, as it isn't
|
43
41
|
# supposed to represent a table
|
44
42
|
auto_eval true do
|
45
|
-
|
43
|
+
next if self.basename == "Default"
|
44
|
+
default = self.superclass.basename.snake_case.pluralize.intern
|
46
45
|
if @dataset && @dataset.opts[:from] != [ default ]
|
47
46
|
# don't clobber dataset from autoloaded file
|
48
|
-
|
49
|
-
|
50
|
-
set_dataset Waves.main.database[ basename.snake_case.pluralize.intern ]
|
51
|
-
end
|
47
|
+
elsif respond_to? :set_dataset
|
48
|
+
set_dataset Waves.main.database[ basename.snake_case.pluralize.intern ]
|
52
49
|
end
|
53
50
|
end
|
51
|
+
|
54
52
|
end
|
55
|
-
|
53
|
+
|
56
54
|
Waves::Controllers::Base.instance_eval do
|
57
55
|
include Waves::Layers::ORM::Sequel::ControllerMethods
|
58
56
|
end
|
59
|
-
|
57
|
+
|
60
58
|
end
|
61
59
|
|
62
60
|
# Mixed into Waves::Controllers::Base. Provides ORM-specific helper methods for model access.
|
@@ -64,27 +62,28 @@ module Waves
|
|
64
62
|
def all
|
65
63
|
model.all
|
66
64
|
end
|
67
|
-
|
65
|
+
|
68
66
|
def find( name )
|
69
67
|
model[ :name => name ] or not_found
|
70
68
|
end
|
71
|
-
|
72
|
-
def create
|
73
|
-
|
69
|
+
|
70
|
+
def create(attrs = nil)
|
71
|
+
ats = attrs || attributes
|
72
|
+
model.create( ats.to_hash )
|
74
73
|
end
|
75
|
-
|
74
|
+
|
76
75
|
def delete( name )
|
77
76
|
find( name ).destroy
|
78
77
|
end
|
79
|
-
|
78
|
+
|
80
79
|
def update( name )
|
81
80
|
instance = find( name )
|
82
81
|
instance.update_with_params( attributes.to_hash )
|
83
82
|
instance
|
84
83
|
end
|
85
84
|
end
|
86
|
-
|
87
|
-
end
|
85
|
+
|
86
|
+
end
|
88
87
|
end
|
89
88
|
end
|
90
89
|
end
|
File without changes
|
@@ -8,7 +8,7 @@ namespace :generate do
|
|
8
8
|
|
9
9
|
raise "Cannot generate Default yet" if model_name == 'Default'
|
10
10
|
|
11
|
-
filename = File.expand_path "models/#{
|
11
|
+
filename = File.expand_path "models/#{model_name}.rb"
|
12
12
|
if File.exist?(filename)
|
13
13
|
$stderr.puts "#{filename} already exists"
|
14
14
|
exit
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "#{File.dirname(__FILE__)}/../../../migration"
|
2
|
+
require 'sequel/extensions/migration'
|
2
3
|
|
3
4
|
namespace :schema do
|
4
5
|
|
@@ -9,6 +10,7 @@ namespace :schema do
|
|
9
10
|
|
10
11
|
desc "Performs Sequel migrations to version=<version>"
|
11
12
|
task :migrate do |task|
|
13
|
+
|
12
14
|
version = ENV['version']; version = version.to_i unless version.nil?
|
13
15
|
Sequel::Migrator.apply( Waves.main.database, Waves::Layers::ORM.migration_directory , version )
|
14
16
|
end
|