mirror of
https://github.com/heartcombo/devise.git
synced 2022-11-09 12:18:31 -05:00
KISS.
This commit is contained in:
parent
ae0a3d9fee
commit
e144ce29c9
3 changed files with 5 additions and 34 deletions
|
@ -16,26 +16,6 @@ module Devise
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
TRUE_VALUES = [true, 1, '1', 't', 'T', 'true', 'TRUE'].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
|
end
|
||||||
|
|
||||||
require 'devise/warden'
|
require 'devise/warden'
|
||||||
|
|
|
@ -47,7 +47,6 @@ module Devise
|
||||||
#
|
#
|
||||||
def devise(*modules)
|
def devise(*modules)
|
||||||
options = modules.extract_options!
|
options = modules.extract_options!
|
||||||
options.assert_valid_keys(:except, *Devise::MODEL_CONFIG)
|
|
||||||
|
|
||||||
modules = Devise::ALL if modules.include?(:all)
|
modules = Devise::ALL if modules.include?(:all)
|
||||||
modules -= Array(options.delete(:except)) if options.key?(:except)
|
modules -= Array(options.delete(:except)) if options.key?(:except)
|
||||||
|
@ -58,17 +57,8 @@ module Devise
|
||||||
include Devise::Models.const_get(m.to_s.classify)
|
include Devise::Models.const_get(m.to_s.classify)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert new keys to methods which overwrites Devise defaults
|
|
||||||
options.each do |key, value|
|
options.each do |key, value|
|
||||||
if value.is_a?(Proc)
|
self.send(:"#{key}=", value)
|
||||||
define_method key, &value
|
|
||||||
else
|
|
||||||
class_eval <<-END_EVAL, __FILE__, __LINE__
|
|
||||||
def #{key}
|
|
||||||
#{value.inspect}
|
|
||||||
end
|
|
||||||
END_EVAL
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -24,13 +24,14 @@ module Devise
|
||||||
# User.find(1).valid_password?('password123') # returns true/false
|
# User.find(1).valid_password?('password123') # returns true/false
|
||||||
#
|
#
|
||||||
module Authenticable
|
module Authenticable
|
||||||
Devise.model_config(self, :pepper)
|
|
||||||
Devise.model_config(self, :stretches, 10)
|
|
||||||
|
|
||||||
def self.included(base)
|
def self.included(base)
|
||||||
base.class_eval do
|
base.class_eval do
|
||||||
extend ClassMethods
|
extend ClassMethods
|
||||||
|
|
||||||
|
cattr_accessor :pepper, :stretches, :instance_writer => false
|
||||||
|
protected :pepper, :stretches
|
||||||
|
self.pepper, self.stretches = nil, 10
|
||||||
|
|
||||||
attr_reader :password
|
attr_reader :password
|
||||||
attr_accessor :password_confirmation
|
attr_accessor :password_confirmation
|
||||||
attr_accessible :email, :password, :password_confirmation
|
attr_accessible :email, :password, :password_confirmation
|
||||||
|
|
Loading…
Reference in a new issue