lib/devise/models.rb in devise-1.1.rc0 vs lib/devise/models.rb in devise-1.1.rc1
- old
+ new
@@ -1,7 +1,19 @@
module Devise
module Models
+ class << self
+ def hook(base)
+ base.class_eval do
+ class_attribute :devise_modules, :instance_writer => false
+ self.devise_modules ||= []
+ end
+ end
+
+ alias :included :hook
+ alias :extended :hook
+ end
+
# Creates configuration values for Devise and for the given module.
#
# Devise::Models.config(Devise::Authenticable, :stretches, 10)
#
# The line above creates:
@@ -43,36 +55,34 @@
# You can also give any of the devise configuration values in form of a hash,
# with specific values for this model. Please check your Devise initializer
# for a complete description on those values.
#
def devise(*modules)
- raise "You need to give at least one Devise module" if modules.empty?
+ include Devise::Models::Authenticatable
options = modules.extract_options!
if modules.delete(:authenticatable)
ActiveSupport::Deprecation.warn ":authenticatable as module is deprecated. Please give :database_authenticatable instead.", caller
modules << :database_authenticatable
end
+ if modules.delete(:activatable)
+ ActiveSupport::Deprecation.warn ":activatable as module is deprecated. It's included in your model by default.", caller
+ end
+
if modules.delete(:http_authenticatable)
ActiveSupport::Deprecation.warn ":http_authenticatable as module is deprecated and is on by default. Revert by setting :http_authenticatable => false.", caller
end
- @devise_modules = Devise::ALL & modules.map(&:to_sym).uniq
+ self.devise_modules += Devise::ALL & modules.map(&:to_sym).uniq
devise_modules_hook! do
- @devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
+ devise_modules.each { |m| include Devise::Models.const_get(m.to_s.classify) }
options.each { |key, value| send(:"#{key}=", value) }
end
end
- # Stores all modules included inside the model, so we are able to verify
- # which routes are needed.
- def devise_modules
- @devise_modules ||= []
- end
-
# The hook which is called inside devise. So your ORM can include devise
# compatibility stuff.
def devise_modules_hook!
yield
end
@@ -98,5 +108,7 @@
record
end
end
end
+
+require 'devise/models/authenticatable'
\ No newline at end of file