From 4c81ecae53ad451171b1ace3dd25249ef74d9465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Valim?= Date: Wed, 18 Nov 2009 09:41:42 -0200 Subject: [PATCH] Mongomapper ORM now converts DateTime to Time. --- CHANGELOG.rdoc | 5 +++++ lib/devise.rb | 9 +++++++-- lib/devise/orm/mongo_mapper.rb | 7 +++++-- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.rdoc b/CHANGELOG.rdoc index 011c3f11..ddbed5f5 100644 --- a/CHANGELOG.rdoc +++ b/CHANGELOG.rdoc @@ -1,6 +1,11 @@ +* bug fix + * MongoMapper now converts DateTime to Time + * enhancements * [#35] Moved friendly_token to Devise * Added Devise.all, so you can freeze your app strategies + * Added Devise.apply_schema, so you can turn it to false in Datamapper or MongoMapper + in cases you don't want it be handlded automatically == 0.5.2 diff --git a/lib/devise.rb b/lib/devise.rb index db3338b1..108eace8 100644 --- a/lib/devise.rb +++ b/lib/devise.rb @@ -25,7 +25,7 @@ module Devise :authlogic_sha512 => 128 } - # Used to encrypt password. Please generate one with rake secret + # Used to encrypt password. Please generate one with rake secret. mattr_accessor :pepper @@pepper = nil @@ -64,10 +64,15 @@ module Devise mattr_accessor :orm @@orm = :active_record - # Configure default options used in :all + # Configure default options used in :all. mattr_accessor :all @@all = Devise::ALL.dup + # Tells if devise should apply the schema in ORMs where devise declaration + # and schema belongs to the same class (as Datamapper and MongoMapper). + mattr_accessor :apply_schema + @@apply_schema = true + class << self # Default way to setup Devise. Run script/generate devise_install to create # a fresh initializer with all configuration values. diff --git a/lib/devise/orm/mongo_mapper.rb b/lib/devise/orm/mongo_mapper.rb index f6aba195..6adb721f 100644 --- a/lib/devise/orm/mongo_mapper.rb +++ b/lib/devise/orm/mongo_mapper.rb @@ -12,12 +12,15 @@ module Devise include Devise::Schema - # Tell how to apply schema methods. + # Tell how to apply schema methods. This automatically converts DateTime + # to Time, since MongoMapper does not recognize the former. def apply_schema(name, type, options={}) + return unless Devise.apply_schema + type = Time if type == DateTime key name, type, options end end end end -MongoMapper::Document::ClassMethods.send(:include, Devise::Models) \ No newline at end of file +MongoMapper::Document::ClassMethods.send(:include, Devise::Models)