Skip to content
Browse files

Tested and refactored Sequel version detection with new Sequel 3.

  • Loading branch information...
1 parent 2182068 commit 2adbbe55c33de5b99afe239fd025a17a44231379 @pk committed May 4, 2009
Showing with 23 additions and 14 deletions.
  1. +8 −0 lib/merb/orms/sequel/connection.rb
  2. +14 −13 lib/merb/session/sequel_session.rb
  3. +1 −1 lib/merb_sequel/merbtasks.rb
View
8 lib/merb/orms/sequel/connection.rb
@@ -10,6 +10,14 @@ class << self
def config_file() Merb.dir_for(:config) / "database.yml" end
def sample_dest() Merb.dir_for(:config) / "database.yml.sample" end
def sample_source() File.dirname(__FILE__) / "database.yml.sample" end
+
+ # Determine if we use Sequel 3 or not
+ #
+ # ==== Returns
+ # Boolean:: True if using Sequel >= 2.12.0 or False
+ def new_sequel?
+ /^(2.12|3)/ =~ ::Sequel.version
+ end
def copy_sample_config
FileUtils.cp sample_source, sample_dest unless File.exists?(sample_dest)
View
27 lib/merb/session/sequel_session.rb
@@ -1,6 +1,5 @@
require 'sequel'
-# Load extensions if we use new versions of Sequel
-require 'sequel/extensions/migration' if /^(2.12|3)/ =~ Sequel.version
+require 'sequel/extensions/migration' if Merb::Orms::Sequel.new_sequel?
require 'merb-core/dispatch/session'
require 'base64'
@@ -79,8 +78,10 @@ def data_column_size_limit
512 # TODO - figure out how much space we actually have
end
- alias :create_table! :create_table
- alias :drop_table! :drop_table
+ unless Merb::Orms::Sequel.new_sequel?
+ alias :create_table! :create_table
+ alias :drop_table! :drop_table
+ end
end
# Lazy-unserialize session state.
@@ -98,6 +99,15 @@ def loaded?
!!@data
end
+ if Merb::Orms::Sequel.new_sequel?
+ def before_save
+ super
+ prepare_data_to_save
+ end
+ else
+ before_save :prepare_data_to_save
+ end
+
private
def prepare_data_to_save
@@ -107,15 +117,6 @@ def prepare_data_to_save
end
end
- if /^(2.12|3)/ =~ Sequel.version
- def before_save
- super
- prepare_data_to_save
- end
- else
- before_save :prepare_data_to_save
- end
-
end
class SequelSession < SessionStoreContainer
View
2 lib/merb_sequel/merbtasks.rb
@@ -11,7 +11,7 @@
desc "Perform migration using migrations in schema/migrations"
task :migrate => :sequel_env do
- require 'sequel/extensions/migration' if /^(2.12|3)/ =~ Sequel.version
+ require 'sequel/extensions/migration' if Merb::Orms::Sequel.new_sequel?
Sequel::Migrator.apply(Sequel::Model.db, "schema/migrations", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
end

0 comments on commit 2adbbe5

Please sign in to comment.
Something went wrong with that request. Please try again.