waves-edge 2009.03.10.13.14
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/waves +30 -0
- data/doc/HISTORY +1 -0
- data/doc/LICENSE +22 -0
- data/doc/README +1 -0
- data/doc/VERSION +1 -0
- data/lib/caches/file.rb +48 -0
- data/lib/caches/memcached.rb +40 -0
- data/lib/caches/simple.rb +25 -0
- data/lib/caches/synchronized.rb +25 -0
- data/lib/commands/console.rb +35 -0
- data/lib/commands/generate.rb +52 -0
- data/lib/commands/help.rb +5 -0
- data/lib/commands/server.rb +68 -0
- data/lib/dispatchers/base.rb +68 -0
- data/lib/dispatchers/default.rb +25 -0
- data/lib/ext/float.rb +13 -0
- data/lib/ext/hash.rb +31 -0
- data/lib/ext/integer.rb +27 -0
- data/lib/ext/kernel.rb +20 -0
- data/lib/ext/module.rb +20 -0
- data/lib/ext/object.rb +33 -0
- data/lib/ext/string.rb +20 -0
- data/lib/ext/symbol.rb +11 -0
- data/lib/ext/tempfile.rb +5 -0
- data/lib/foundations/classic.rb +59 -0
- data/lib/foundations/compact.rb +52 -0
- data/lib/helpers/basic.rb +11 -0
- data/lib/helpers/doc_type.rb +34 -0
- data/lib/helpers/extended.rb +21 -0
- data/lib/helpers/form.rb +42 -0
- data/lib/helpers/formatting.rb +30 -0
- data/lib/helpers/layouts.rb +37 -0
- data/lib/helpers/model.rb +37 -0
- data/lib/helpers/view.rb +22 -0
- data/lib/layers/inflect/english.rb +35 -0
- data/lib/layers/mvc.rb +41 -0
- data/lib/layers/mvc/controllers.rb +41 -0
- data/lib/layers/mvc/extensions.rb +52 -0
- data/lib/layers/orm/migration.rb +79 -0
- data/lib/layers/orm/providers/active_record.rb +84 -0
- data/lib/layers/orm/providers/active_record/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/providers/active_record/tasks/generate.rb +28 -0
- data/lib/layers/orm/providers/active_record/tasks/schema.rb +22 -0
- data/lib/layers/orm/providers/data_mapper.rb +37 -0
- data/lib/layers/orm/providers/filebase.rb +25 -0
- data/lib/layers/orm/providers/sequel.rb +87 -0
- data/lib/layers/orm/providers/sequel/migrations/empty.rb.erb +9 -0
- data/lib/layers/orm/providers/sequel/tasks/generate.rb +30 -0
- data/lib/layers/orm/providers/sequel/tasks/schema.rb +16 -0
- data/lib/layers/renderers/erubis.rb +52 -0
- data/lib/layers/renderers/haml.rb +67 -0
- data/lib/layers/renderers/markaby.rb +41 -0
- data/lib/matchers/accept.rb +21 -0
- data/lib/matchers/base.rb +30 -0
- data/lib/matchers/content_type.rb +17 -0
- data/lib/matchers/path.rb +67 -0
- data/lib/matchers/query.rb +21 -0
- data/lib/matchers/request.rb +27 -0
- data/lib/matchers/resource.rb +19 -0
- data/lib/matchers/traits.rb +19 -0
- data/lib/matchers/uri.rb +20 -0
- data/lib/renderers/mixin.rb +13 -0
- data/lib/resources/mixin.rb +136 -0
- data/lib/resources/paths.rb +132 -0
- data/lib/runtime/configuration.rb +100 -0
- data/lib/runtime/console.rb +23 -0
- data/lib/runtime/logger.rb +35 -0
- data/lib/runtime/mime_types.rb +536 -0
- data/lib/runtime/mocks.rb +14 -0
- data/lib/runtime/monitor.rb +32 -0
- data/lib/runtime/request.rb +152 -0
- data/lib/runtime/response.rb +43 -0
- data/lib/runtime/response_mixin.rb +54 -0
- data/lib/runtime/runtime.rb +69 -0
- data/lib/runtime/server.rb +20 -0
- data/lib/runtime/session.rb +27 -0
- data/lib/runtime/worker.rb +86 -0
- data/lib/servers/base.rb +42 -0
- data/lib/servers/mongrel.rb +13 -0
- data/lib/servers/webrick.rb +13 -0
- data/lib/tasks/gem.rb +32 -0
- data/lib/tasks/generate.rb +85 -0
- data/lib/views/errors.rb +49 -0
- data/lib/views/mixin.rb +64 -0
- data/lib/waves.rb +63 -0
- data/samples/blog/Rakefile +25 -0
- data/samples/blog/configurations/default.rb +11 -0
- data/samples/blog/configurations/development.rb +29 -0
- data/samples/blog/configurations/production.rb +26 -0
- data/samples/blog/models/comment.rb +23 -0
- data/samples/blog/models/entry.rb +31 -0
- data/samples/blog/public/css/site.css +13 -0
- data/samples/blog/public/javascript/jquery-1.2.6.min.js +32 -0
- data/samples/blog/public/javascript/site.js +13 -0
- data/samples/blog/resources/entry.rb +39 -0
- data/samples/blog/resources/map.rb +9 -0
- data/samples/blog/schema/migrations/001_initial_schema.rb +17 -0
- data/samples/blog/schema/migrations/002_add_comments.rb +18 -0
- data/samples/blog/schema/migrations/templates/empty.rb.erb +9 -0
- data/samples/blog/startup.rb +8 -0
- data/samples/blog/templates/comment/add.mab +12 -0
- data/samples/blog/templates/comment/list.mab +6 -0
- data/samples/blog/templates/entry/edit.mab +14 -0
- data/samples/blog/templates/entry/list.mab +16 -0
- data/samples/blog/templates/entry/show.mab +18 -0
- data/samples/blog/templates/entry/summary.mab +9 -0
- data/samples/blog/templates/errors/not_found_404.mab +7 -0
- data/samples/blog/templates/errors/server_error_500.mab +2 -0
- data/samples/blog/templates/layouts/default.mab +19 -0
- data/samples/blog/templates/waves/status.mab +85 -0
- data/templates/classic/Rakefile +90 -0
- data/templates/classic/configurations/default.rb.erb +9 -0
- data/templates/classic/configurations/development.rb.erb +26 -0
- data/templates/classic/configurations/production.rb.erb +29 -0
- data/templates/classic/controllers/.gitignore +0 -0
- data/templates/classic/helpers/.gitignore +0 -0
- data/templates/classic/lib/tasks/.gitignore +0 -0
- data/templates/classic/models/.gitignore +0 -0
- data/templates/classic/public/css/.gitignore +0 -0
- data/templates/classic/public/flash/.gitignore +0 -0
- data/templates/classic/public/images/.gitignore +0 -0
- data/templates/classic/public/javascript/.gitignore +0 -0
- data/templates/classic/resources/.gitignore +0 -0
- data/templates/classic/resources/map.rb.erb +8 -0
- data/templates/classic/schema/migrations/.gitignore +0 -0
- data/templates/classic/startup.rb.erb +11 -0
- data/templates/classic/templates/errors/not_found_404.mab +7 -0
- data/templates/classic/templates/errors/server_error_500.mab +7 -0
- data/templates/classic/templates/layouts/default.mab +14 -0
- data/templates/classic/tmp/sessions/.gitignore +0 -0
- data/templates/classic/views/.gitignore +0 -0
- data/templates/compact/startup.rb.erb +11 -0
- 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 +34 -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 +40 -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 +55 -0
- data/test/views/views.rb +34 -0
- metadata +394 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
module Helpers
|
4
|
+
|
5
|
+
module Layouts
|
6
|
+
|
7
|
+
# Invokes a layout view (i.e., a view from the layouts template directory), using
|
8
|
+
# the assigns parameter to define instance variables for the view. The block is
|
9
|
+
# evaluated and also passed into the view as the +layout_content+ instance variable.
|
10
|
+
#
|
11
|
+
# You can define a layout just by creating a template and then calling the
|
12
|
+
# +layout_content+ accessor when you want to embed the caller's content.
|
13
|
+
#
|
14
|
+
# == Example
|
15
|
+
#
|
16
|
+
# doctype :html4_transitional
|
17
|
+
# html do
|
18
|
+
# title @title # passed as an assigns parameter
|
19
|
+
# end
|
20
|
+
# body do
|
21
|
+
# layout_content
|
22
|
+
# end
|
23
|
+
#
|
24
|
+
def layout( name, assigns = {}, &block )
|
25
|
+
assigns[ :layout_content ] = capture(&block)
|
26
|
+
self << Waves.main::Views[:layouts].process( request ) do
|
27
|
+
send( name, assigns )
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def layout_content
|
32
|
+
self << @layout_content
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# Model helpers allow you to directly access a model from within a view.
|
5
|
+
# This is useful when creating things like select boxes that need data
|
6
|
+
# from anther model. For example, a Markaby select box for authors might look like:
|
7
|
+
#
|
8
|
+
# select do
|
9
|
+
# all(:user).each do |user|
|
10
|
+
# option user.full_name, :value => user.id
|
11
|
+
# end
|
12
|
+
# end
|
13
|
+
#
|
14
|
+
# You could also use these within a view class to keep model-based logic out
|
15
|
+
# of the templates themselves. For example, in the view class you might define
|
16
|
+
# a method called +authors+ that returns an array of name / id pairs. This could
|
17
|
+
# then be called from the template instead of the model helper.
|
18
|
+
#
|
19
|
+
module Model
|
20
|
+
|
21
|
+
def model( name )
|
22
|
+
Waves.main::Models[ name ][ domain ]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Just like model.all. Returns all the instances of that model.
|
26
|
+
def all( model )
|
27
|
+
model( model ).all
|
28
|
+
end
|
29
|
+
|
30
|
+
# Finds a specific instance using the name field
|
31
|
+
def find( model, name )
|
32
|
+
model( model )[name ] rescue nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/helpers/view.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module Waves
|
2
|
+
module Helpers
|
3
|
+
|
4
|
+
# View helpers are intended to help reuse views from within other views.
|
5
|
+
# Both the +layout+ method in the common helpers and the +property+ method
|
6
|
+
# of the form helpers are specialized instance of this.
|
7
|
+
#
|
8
|
+
# The star of our show here is the +view+ method. This takes a model, view,
|
9
|
+
# and assigns hash (which are converted into instance variables in the target
|
10
|
+
# view) and returns the result of evaluating the view as content in the current
|
11
|
+
# template.
|
12
|
+
module View
|
13
|
+
|
14
|
+
# Invokes the view for the given model, passing the assigns as instance variables.
|
15
|
+
def view( model, view, assigns = {} )
|
16
|
+
self << Waves.main::Views[ model ].new( request ).send( view, assigns )
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
module Inflect
|
4
|
+
|
5
|
+
# Adds plural/singular methods for English to String
|
6
|
+
module English
|
7
|
+
|
8
|
+
def self.included(app)
|
9
|
+
|
10
|
+
require 'english/inflect'
|
11
|
+
|
12
|
+
Waves::Resources::Mixin::ClassMethods.module_eval do
|
13
|
+
def singular ; basename.snake_case.singular ; end
|
14
|
+
def plural ; basename.snake_case.plural ; end
|
15
|
+
end
|
16
|
+
|
17
|
+
Waves::Resources::Mixin.module_eval do
|
18
|
+
def singular ; self.class.singular ; end
|
19
|
+
def plural ; self.class.plural ; end
|
20
|
+
end
|
21
|
+
|
22
|
+
Waves::Resources::Paths.module_eval do
|
23
|
+
def resource ; self.class.resource.singular ; end
|
24
|
+
def resources ; self.class.resource.plural ; end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
|
data/lib/layers/mvc.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
module MVC
|
4
|
+
|
5
|
+
def self.included( app )
|
6
|
+
|
7
|
+
require 'layers/mvc/extensions'
|
8
|
+
require 'layers/mvc/controllers'
|
9
|
+
|
10
|
+
app.auto_create_module( :Models ) do
|
11
|
+
auto_create_class :Default
|
12
|
+
auto_load :Default, :directories => [ :models ]
|
13
|
+
auto_create_class true, :Default
|
14
|
+
auto_load true, :directories => [ :models ]
|
15
|
+
end
|
16
|
+
|
17
|
+
app.auto_create_module( :Views ) do
|
18
|
+
auto_create_class :Default, Waves::Views::Base
|
19
|
+
auto_load :Default, :directories => [ :views ]
|
20
|
+
auto_create_class true, :Default
|
21
|
+
auto_load true, :directories => [ :views ]
|
22
|
+
end
|
23
|
+
|
24
|
+
app.auto_create_module( :Controllers ) do
|
25
|
+
auto_create_class :Default, Waves::Controllers::Base
|
26
|
+
auto_load :Default, :directories => [ :controllers ]
|
27
|
+
auto_create_class true, :Default
|
28
|
+
auto_load true, :directories => [ :controllers ]
|
29
|
+
end
|
30
|
+
|
31
|
+
app.auto_create_module( :Helpers ) do
|
32
|
+
auto_create_module( :Default ) { include Waves::Helpers::Extended }
|
33
|
+
auto_load :Default, :directories => [ :helpers ]
|
34
|
+
auto_create_module( true ) { include app::Helpers::Default }
|
35
|
+
auto_load true, :directories => [ :helpers ]
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
module Controllers
|
4
|
+
|
5
|
+
module Mixin
|
6
|
+
|
7
|
+
attr_reader :request
|
8
|
+
|
9
|
+
include Waves::ResponseMixin
|
10
|
+
|
11
|
+
def initialize( request )
|
12
|
+
@request = request
|
13
|
+
end
|
14
|
+
|
15
|
+
def find( name )
|
16
|
+
model.find( name )
|
17
|
+
end
|
18
|
+
|
19
|
+
def create( attributes )
|
20
|
+
model.create( attributes )
|
21
|
+
end
|
22
|
+
|
23
|
+
def update( name, attributes )
|
24
|
+
find( name ).attributes = attributes
|
25
|
+
end
|
26
|
+
|
27
|
+
def delete( name )
|
28
|
+
model.delete( name )
|
29
|
+
end
|
30
|
+
|
31
|
+
def list
|
32
|
+
model.all
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class Base ; include Mixin ; end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Waves
|
2
|
+
|
3
|
+
module Resources
|
4
|
+
|
5
|
+
module Mixin
|
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
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
module ResponseMixin
|
22
|
+
|
23
|
+
# Returns the name of the model corresponding to this controller by taking the basename
|
24
|
+
# of the module and converting it to snake case. If the model plurality is different than
|
25
|
+
# the controller, this will not, in fact, be the model name.
|
26
|
+
def model_name; self.class.basename.snake_case; end
|
27
|
+
|
28
|
+
# Returns the model corresponding to this controller by naively assuming that
|
29
|
+
# +model_name+ must be correct. This allows you to write generic controller methods such as:
|
30
|
+
#
|
31
|
+
# model.find( name )
|
32
|
+
#
|
33
|
+
# to find an instance of a given model. Again, the plurality of the controller and
|
34
|
+
# model must be the same for this to work.
|
35
|
+
def model; app::Models[ model_name.intern ]; end
|
36
|
+
|
37
|
+
# MVC Params get automatically destructured with the keys as accessors methods.
|
38
|
+
# You can still access the original query by calling request.query
|
39
|
+
def query
|
40
|
+
@query ||= Waves::Request::Query.new(
|
41
|
+
Waves::Request::Utilities.destructure( request.query ) )
|
42
|
+
end
|
43
|
+
|
44
|
+
# Attributes are just the query elements specific to the model associated with
|
45
|
+
# the current resource.
|
46
|
+
def attributes
|
47
|
+
query[ model_name ]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
|
4
|
+
# Helper methods to establish inter-ORM standards
|
5
|
+
module ORM
|
6
|
+
|
7
|
+
# Glob pattern
|
8
|
+
MIGRATION_FILE_PATTERN = '[0-9][0-9][0-9]_*.rb'.freeze
|
9
|
+
|
10
|
+
def self.create_migration_for(orm)
|
11
|
+
source = migration_template(orm.to_s.snake_case, ENV['template'])
|
12
|
+
destination = migration_destination(ENV['name'])
|
13
|
+
migration_name = migration_name(ENV['name'])
|
14
|
+
|
15
|
+
context = {:class_name => migration_name.camel_case}
|
16
|
+
|
17
|
+
write_migration(context, source, destination)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Where Waves keeps its migration files
|
21
|
+
def self.migration_directory
|
22
|
+
:schema / :migrations
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns any found migration files in the supplied directory.
|
26
|
+
def self.migration_files(range = nil)
|
27
|
+
pattern = migration_directory / MIGRATION_FILE_PATTERN
|
28
|
+
files = Dir[pattern].inject([]) do |m, path|
|
29
|
+
m[File.basename(path).to_i] = path
|
30
|
+
m
|
31
|
+
end
|
32
|
+
filtered = range ? files[range] : files
|
33
|
+
filtered ? filtered.compact : []
|
34
|
+
end
|
35
|
+
|
36
|
+
# Use the supplied version number or determine the next in sequence
|
37
|
+
# based on the migration files in the migration directory
|
38
|
+
def self.next_migration_version
|
39
|
+
version = ENV['version'] || latest_migration_version
|
40
|
+
version.to_i + 1
|
41
|
+
end
|
42
|
+
|
43
|
+
# Uses the migration files in the migration directory to determine
|
44
|
+
# the highest numbered existing migration.
|
45
|
+
def self.latest_migration_version
|
46
|
+
l = migration_files.last
|
47
|
+
l ? File.basename(l).to_i : nil
|
48
|
+
end
|
49
|
+
|
50
|
+
# If the user doesn't pass a name, defaults to "migration"
|
51
|
+
def self.migration_name(name=nil)
|
52
|
+
name || 'migration'
|
53
|
+
end
|
54
|
+
|
55
|
+
# Returns the path to the migration template file for the given ORM.
|
56
|
+
# <em>orm</em> can be a symbol or string
|
57
|
+
def self.migration_template(orm, name=nil)
|
58
|
+
file = ( name || 'empty' ) + '.rb.erb'
|
59
|
+
source = File.dirname(__FILE__) / :providers / orm / :migrations / file
|
60
|
+
end
|
61
|
+
|
62
|
+
# Given a migration name, returns the path of the file that would be created.
|
63
|
+
def self.migration_destination(name)
|
64
|
+
version = next_migration_version
|
65
|
+
migration_directory / "#{'%03d' % version}_#{migration_name(name)}.rb"
|
66
|
+
end
|
67
|
+
|
68
|
+
# Takes an assigns hash as the Erubis context. Keys in the hash become
|
69
|
+
# instance variable names.
|
70
|
+
def self.write_migration(context, source, destination)
|
71
|
+
code = Erubis::Eruby.new( File.read( source ) ).evaluate( context )
|
72
|
+
puts "Creating #{destination}"
|
73
|
+
File.write( destination, code )
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Waves
|
2
|
+
module Layers
|
3
|
+
module ORM
|
4
|
+
|
5
|
+
# Sets up the ActiveRecord connection and configures AutoCode on Models, so that constants in that
|
6
|
+
# namespace get loaded from file or created as subclasses of Models::Default
|
7
|
+
module ActiveRecord
|
8
|
+
|
9
|
+
# On inclusion, this module:
|
10
|
+
# - creates on the application module a database method that establishes and returns the ActiveRecord connection
|
11
|
+
# - arranges for autoloading/autocreation of missing constants in the Models namespace
|
12
|
+
# - defines ActiveRecord-specific helper methods on Waves::Controllers::Base
|
13
|
+
#
|
14
|
+
# The controller helper methdods are:
|
15
|
+
# - all
|
16
|
+
# - find(name)
|
17
|
+
# - create
|
18
|
+
# - delete(name)
|
19
|
+
# - update(name)
|
20
|
+
|
21
|
+
|
22
|
+
def self.included(app)
|
23
|
+
|
24
|
+
require 'active_record'
|
25
|
+
require "#{File.dirname(__FILE__)}/active_record/tasks/schema" if defined?(Rake)
|
26
|
+
require "#{File.dirname(__FILE__)}/active_record/tasks/generate" if defined?(Rake)
|
27
|
+
|
28
|
+
def app.database
|
29
|
+
unless @database
|
30
|
+
::ActiveRecord::Base.establish_connection(config.database)
|
31
|
+
@database = ::ActiveRecord::Base.connection
|
32
|
+
end
|
33
|
+
@database
|
34
|
+
end
|
35
|
+
|
36
|
+
app.auto_create_module( :Models ) do
|
37
|
+
auto_create_class :Default, ::ActiveRecord::Base
|
38
|
+
auto_load :Default, :directories => [ :models ]
|
39
|
+
auto_create_class true, app::Models::Default
|
40
|
+
auto_load true, :directories => [ :models ]
|
41
|
+
|
42
|
+
auto_eval true do
|
43
|
+
next if self.basename == "Default"
|
44
|
+
app.database
|
45
|
+
set_table_name self.basename.snake_case.pluralize.intern
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Waves::Controllers::Base.instance_eval do
|
50
|
+
include Waves::Layers::ORM::ActiveRecord::ControllerMethods
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
# Mixed into Waves::Controllers::Base. Provides ORM-specific helper methods for model access.
|
56
|
+
module ControllerMethods
|
57
|
+
def all
|
58
|
+
model.find(:all)
|
59
|
+
end
|
60
|
+
|
61
|
+
def find( name )
|
62
|
+
model.find_by_name(name) or not_found
|
63
|
+
end
|
64
|
+
|
65
|
+
def create
|
66
|
+
model.create( attributes )
|
67
|
+
end
|
68
|
+
|
69
|
+
def delete( name )
|
70
|
+
find( name ).destroy
|
71
|
+
end
|
72
|
+
|
73
|
+
def update( name )
|
74
|
+
instance = find( name )
|
75
|
+
instance.update_attributes( attributes )
|
76
|
+
instance
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|