1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Revert "KISS."

Simpler doesn't work here.

This reverts commit e144ce29c9.
This commit is contained in:
José Valim 2009-10-20 12:49:49 -02:00
parent e144ce29c9
commit cbb4796599
3 changed files with 34 additions and 5 deletions

View file

@ -16,6 +16,26 @@ module Devise
}.freeze
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].freeze
MODEL_CONFIG = []
def self.model_config(klass, accessor, default=nil)
# Create Devise accessor
mattr_accessor accessor
# Set default value
send(:"#{accessor}=", default)
# Store configuration method
MODEL_CONFIG << accessor
# Set default value
klass.class_eval <<-METHOD
def #{accessor}
Devise.#{accessor}
end
METHOD
end
end
require 'devise/warden'

View file

@ -47,6 +47,7 @@ module Devise
#
def devise(*modules)
options = modules.extract_options!
options.assert_valid_keys(:except, *Devise::MODEL_CONFIG)
modules = Devise::ALL if modules.include?(:all)
modules -= Array(options.delete(:except)) if options.key?(:except)
@ -57,8 +58,17 @@ module Devise
include Devise::Models.const_get(m.to_s.classify)
end
# Convert new keys to methods which overwrites Devise defaults
options.each do |key, value|
self.send(:"#{key}=", value)
if value.is_a?(Proc)
define_method key, &value
else
class_eval <<-END_EVAL, __FILE__, __LINE__
def #{key}
#{value.inspect}
end
END_EVAL
end
end
end

View file

@ -24,14 +24,13 @@ module Devise
# User.find(1).valid_password?('password123') # returns true/false
#
module Authenticable
Devise.model_config(self, :pepper)
Devise.model_config(self, :stretches, 10)
def self.included(base)
base.class_eval do
extend ClassMethods
cattr_accessor :pepper, :stretches, :instance_writer => false
protected :pepper, :stretches
self.pepper, self.stretches = nil, 10
attr_reader :password
attr_accessor :password_confirmation
attr_accessible :email, :password, :password_confirmation