Class: Merb::Orms::Sequel::Connect

Inherits:
BootLoader
  • Object
show all
Defined in:
lib/merb_sequel.rb

Overview

Connects to the database and handles session

Connects to the database and loads sequel sessions if we use them. Sets router to identify models using Model.pk.

Class Method Summary collapse

Class Method Details

.load_activemodel_compatibilityObject

Load active model plugin if available

Merb > 1.0.13 expects models to be ActiveModel compatible Sequel 3.5.0 added plugin to make Sequel models AtciveModel compatible.

We’re loading plugin to all models here if plugin is available if the plugin is not available we must include compatibility module.



41
42
43
44
45
46
47
# File 'lib/merb_sequel.rb', line 41

def self.load_activemodel_compatibility
  begin
    Sequel::Model.plugin :active_model
  rescue LoadError, NoMethodError
    Sequel::Model.send(:include, Merb::Orms::Sequel::Model::ActiveModelCompatibility)
  end
end

.runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/merb_sequel.rb', line 17

def self.run
  Merb::Orms::Sequel.connect
  if Merb::Config.session_stores.include?(:sequel)
    Merb.logger.debug "Using Sequel sessions"
    require File.join(File.dirname(__FILE__) / "merb" / "session" / "sequel_session")
  end
  
  # Set identifiy to use Sequel primary key field
  Merb::Router.root_behavior = Merb::Router.root_behavior.identify(Sequel::Model => :pk)

  # Load compatibility extensions
  if Merb::Plugins.config[:merb_sequel][:load_activemodel_compatibility]
    load_activemodel_compatibility
  end
end