Module: Waves::Layers::ORM::Sequel
- Defined in:
- lib/layers/orm/sequel.rb
Overview
Sets up the Sequel connection and configures AutoCode on Models, so that constants in that namespace get loaded from file or created as subclasses of Models::Default
Defined Under Namespace
Modules: ControllerMethods
Class Method Summary collapse
-
.included(app) ⇒ Object
On inclusion, this module: - creates on the application module a database method that establishes the Sequel connection - arranges for autoloading/autocreation of missing constants in the Models namespace - defines Sequel-specific helper methods on Waves::Controllers::Base.
Class Method Details
.included(app) ⇒ Object
On inclusion, this module:
-
creates on the application module a database method that establishes the Sequel connection
-
arranges for autoloading/autocreation of missing constants in the Models namespace
-
defines Sequel-specific helper methods on Waves::Controllers::Base
The controller helper methdods are:
-
all
-
find(name)
-
create
-
delete(name)
-
update(name)
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 |
# File 'lib/layers/orm/sequel.rb', line 26 def self.included(app) def app.database ; @sequel ||= ::Sequel.open( config.database ) ; end app.auto_create_module( :Models ) do include AutoCode auto_create_class :Default, ::Sequel::Model auto_load :Default, :directories => [ :models ] end app.auto_eval :Models do auto_create_class true, app::Models::Default auto_load true, :directories => [ :models ] # set the Sequel dataset based on the model class name # note that this is not done for app::Models::Default, as it isn't # supposed to represent a table auto_eval true do default = superclass.basename.snake_case.pluralize.intern if @dataset && @dataset.opts[:from] != [ default ] # don't clobber dataset from autoloaded file else set_dataset Waves.application.database[ basename.snake_case.pluralize.intern ] end end end Waves::Controllers::Base.instance_eval do include Waves::Layers::ORM::Sequel::ControllerMethods end end |