devise-multi_email 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/devise/multi_email/models/validatable.rb +44 -11
- data/lib/devise/multi_email/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 89e5c38434485cb61230eb832707e8d24e8fc721
|
4
|
+
data.tar.gz: 819986e649a53569de8586df8eb8590853253bc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: add18da49f5a18e6c341ea8c70e69936b54976c2ba322cb2cb1f52e7e0a42cf69136d8b32b45c826f936e8948502282ac20c1d2541b9b8e83cd8d609b62232f2
|
7
|
+
data.tar.gz: df1d574d2300edca58a55ce82a4cae740c97e58a50f4cb8c103c889d1539c052c1a62ffafb1d2a3abb1f4b75dd36640ed3b19843b0437f519085ad1e8ef73968
|
@@ -21,26 +21,55 @@ module Devise
|
|
21
21
|
end
|
22
22
|
|
23
23
|
module MultiEmailValidatable
|
24
|
-
|
24
|
+
def self.required_fields(klass)
|
25
|
+
[]
|
26
|
+
end
|
25
27
|
|
26
|
-
|
27
|
-
|
28
|
-
|
28
|
+
# All validations used by this module.
|
29
|
+
VALIDATIONS = [:validates_presence_of, :validates_uniqueness_of, :validates_format_of,
|
30
|
+
:validates_confirmation_of, :validates_length_of].freeze
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
+
def self.included(base)
|
33
|
+
base.extend ClassMethods
|
34
|
+
assert_validations_api!(base)
|
35
|
+
|
36
|
+
base.class_eval do
|
37
|
+
validates_presence_of :email, if: :email_required?
|
38
|
+
|
39
|
+
validates_presence_of :password, if: :password_required?
|
40
|
+
validates_confirmation_of :password, if: :password_required?
|
41
|
+
validates_length_of :password, within: password_length, allow_blank: true
|
42
|
+
|
43
|
+
after_validation :propagate_email_errors
|
44
|
+
email_class.send :include, EmailValidatable
|
45
|
+
end
|
46
|
+
|
47
|
+
base.devise_modules << :validatable
|
32
48
|
end
|
33
49
|
|
34
|
-
def self.
|
35
|
-
|
50
|
+
def self.assert_validations_api!(base) #:nodoc:
|
51
|
+
unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }
|
52
|
+
|
53
|
+
unless unavailable_validations.empty?
|
54
|
+
raise "Could not use :validatable module since #{base} does not respond " <<
|
55
|
+
"to the following methods: #{unavailable_validations.to_sentence}."
|
56
|
+
end
|
36
57
|
end
|
37
58
|
|
38
|
-
|
59
|
+
protected
|
39
60
|
|
40
|
-
|
41
|
-
|
61
|
+
# Same as Devise::Models::Validatable#password_required?
|
62
|
+
def password_required?
|
63
|
+
!persisted? || !password.nil? || !password_confirmation.nil?
|
64
|
+
end
|
65
|
+
|
66
|
+
# Same as Devise::Models::Validatable#email_required?
|
67
|
+
def email_required?
|
68
|
+
true
|
42
69
|
end
|
43
70
|
|
71
|
+
private
|
72
|
+
|
44
73
|
def propagate_email_errors
|
45
74
|
email_error_key = self.class::EMAILS_ASSOCIATION
|
46
75
|
if respond_to?("#{self.class::EMAILS_ASSOCIATION}_attributes=")
|
@@ -53,6 +82,10 @@ module Devise
|
|
53
82
|
errors.add(:email, error)
|
54
83
|
end
|
55
84
|
end
|
85
|
+
|
86
|
+
module ClassMethods
|
87
|
+
Devise::Models.config(self, :password_length)
|
88
|
+
end
|
56
89
|
end
|
57
90
|
end
|
58
91
|
end
|