Skip to content

Commit

Permalink
Remove deprecation warning, extract SessionSerializer and release new…
Browse files Browse the repository at this point in the history
… version.
  • Loading branch information
josevalim committed Dec 7, 2009
1 parent 35370e9 commit e51e19c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 27 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.rdoc
@@ -1,3 +1,12 @@
== 0.7.0

* deprecations
* :authenticatable is not included by default anymore

* enhancements
* Improve loading process
* Extract SessionSerializer from Authenticatable

== 0.6.3

* bug fix
Expand All @@ -19,7 +28,7 @@
== 0.6.0

* deprecations
* :authenticatable is not included by default anymore
* :authenticatable is still included by default, but yields a deprecation warning

* enhancements
* Added DataMapper support
Expand Down
11 changes: 3 additions & 8 deletions lib/devise/models.rb
Expand Up @@ -3,7 +3,8 @@ module Models
autoload :Authenticatable, 'devise/models/authenticatable'
autoload :Confirmable, 'devise/models/confirmable'
autoload :Recoverable, 'devise/models/recoverable'
autoload :Rememberable, 'devise/models/rememberable'
autoload :Rememberable, 'devise/models/rememberable'
autoload :SessionSerializer, 'devise/models/authenticatable'
autoload :Timeoutable, 'devise/models/timeoutable'
autoload :Trackable, 'devise/models/trackable'
autoload :Validatable, 'devise/models/validatable'
Expand Down Expand Up @@ -77,19 +78,13 @@ def #{accessor}=(value)
# devise :all, :except => :recoverable
#
def devise(*modules)
# TODO Add this check in future versions
# raise "You need to give at least one Devise module" if modules.empty?
raise "You need to give at least one Devise module" if modules.empty?

options = modules.extract_options!
modules = Devise.all if modules.include?(:all)
modules -= Array(options.delete(:except))
modules = Devise::ALL & modules

if !modules.include?(:authenticatable)
modules = [:authenticatable] | modules
ActiveSupport::Deprecation.warn ":authenticatable won't be included by default in devise in future versions, please add it", caller[0,10]
end

Devise.orm_class.included_modules_hook(self, modules) do
modules.each do |m|
devise_modules << m.to_sym
Expand Down
26 changes: 14 additions & 12 deletions lib/devise/models/authenticatable.rb
Expand Up @@ -3,6 +3,19 @@

module Devise
module Models
module SessionSerializer
# Hook to serialize user into session. Overwrite if you want.
def serialize_into_session(record)
[record.class, record.id]
end

# Hook to serialize user from session. Overwrite if you want.
def serialize_from_session(keys)
klass, id = keys
raise "#{self} cannot serialize from #{klass} session since it's not its ancestors" unless klass <= self
klass.find(:first, :conditions => { :id => id })
end
end

# Authenticable Module, responsible for encrypting password and validating
# authenticity of a user while signing in.
Expand Down Expand Up @@ -32,6 +45,7 @@ module Authenticatable
def self.included(base)
base.class_eval do
extend ClassMethods
extend SessionSerializer

attr_reader :password
attr_accessor :password_confirmation
Expand Down Expand Up @@ -71,18 +85,6 @@ def authenticate(attributes={})
valid_for_authentication(resource, attributes) if resource
end

# Hook to serialize user into session. Overwrite if you want.
def serialize_into_session(record)
[record.class, record.id]
end

# Hook to serialize user from session. Overwrite if you want.
def serialize_from_session(keys)
klass, id = keys
raise "#{self} cannot serialize from #{klass} session since it's not its ancestors" unless klass <= self
klass.find(:first, :conditions => { :id => id })
end

# Returns the class for the configured encryptor.
def encryptor_class
@encryptor_class ||= ::Devise::Encryptors.const_get(encryptor.to_s.classify)
Expand Down
5 changes: 0 additions & 5 deletions lib/devise/rails/routes.rb
Expand Up @@ -79,11 +79,6 @@ class Mapper #:doc:
def devise_for(*resources)
options = resources.extract_options!

if singular = options.delete(:singular)
ActiveSupport::Deprecation.warn ":singular is deprecated in devise_for, use :scope instead."
options[:scope] = singular
end

resources.map!(&:to_sym)
resources.each do |resource|
mapping = Devise::Mapping.new(resource, options.dup)
Expand Down
2 changes: 1 addition & 1 deletion lib/devise/version.rb
@@ -1,3 +1,3 @@
module Devise
VERSION = "0.6.3".freeze
VERSION = "0.7.0".freeze
end

0 comments on commit e51e19c

Please sign in to comment.