Module: Waves::Layers::ORM::Sequel
- Defined in:
- lib/waves/layers/orm/providers/sequel.rb
Overview
The Sequel ORM layer 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. The dataset for models is set to the snakecased version of the model’s class name.
Defined Under Namespace
Modules: ControllerMethods
Class Method Summary collapse
Class Method Details
.included(app) ⇒ Object
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 |
# File 'lib/waves/layers/orm/providers/sequel.rb', line 23 def self.included(app) gem 'sequel', '>= 2.0.0' require 'sequel' require "#{File.dirname(__FILE__)}/sequel/tasks/schema" if defined?(Rake) require "#{File.dirname(__FILE__)}/sequel/tasks/generate" if defined?(Rake) def app.database ; @sequel ||= ::Sequel.connect( Waves.config.database ) ; end app.database.loggers << Waves.log app.auto_create_module( :Models ) do auto_create_class :Default, ::Sequel::Model auto_load :Default, :directories => [ :models ] auto_create_class true, :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 next if self.basename == "Default" default = self.superclass.basename.snake_case.pluralize.intern if @dataset && @dataset.opts[:from] != [ default ] # don't clobber dataset from autoloaded file elsif respond_to? :set_dataset set_dataset Waves.main.database[ basename.snake_case.pluralize.intern ] end end end Waves::Controllers::Base.instance_eval do include Waves::Layers::ORM::Sequel::ControllerMethods end end |