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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a2b9c44fd5e0d7e67068e283c110c3d5bcf2578d
4
- data.tar.gz: 6c6101cc82b5f18131fb3a44383953424ad4c433
3
+ metadata.gz: 89e5c38434485cb61230eb832707e8d24e8fc721
4
+ data.tar.gz: 819986e649a53569de8586df8eb8590853253bc0
5
5
  SHA512:
6
- metadata.gz: 77aae6065dcb2ce816df78945ea39addbb4c3550f80252ad5048ea81fbd38f7360ec92678574a554a54591c4c1fac9eee23433935145a1fe2ee2e4e37d563e08
7
- data.tar.gz: ef10791a3e1818069f8138373eb11fb277e63f4fbdaa5c40ed451f9c9bf1a6ea4b756762a94024499aa6389f742fa54ba23084cb31256421819a4f80b463bf0d
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
- extend ActiveSupport::Concern
24
+ def self.required_fields(klass)
25
+ []
26
+ end
25
27
 
26
- included do
27
- devise :validatable
28
- validates Devise::Models::MultiEmailAuthenticatable::EMAILS_ASSOCIATION, presence: true
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
- after_validation :propagate_email_errors
31
- email_class.send :include, EmailValidatable
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.required_fields(klass)
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
- private
59
+ protected
39
60
 
40
- def email_changed?
41
- false
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
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module MultiEmail
3
- VERSION = '1.0.1'
3
+ VERSION = '1.0.2'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-multi_email
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - ALLEN WANG QIANG