Module: Shield::Ohm::EmailPassword

Defined in:
lib/shield/contrib/ohm/email_password.rb

Defined Under Namespace

Modules: Fetch

Constant Summary collapse

EMAIL_REGEX =
/^([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*[\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)$/i

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#passwordObject

Returns the value of attribute password.



32
33
34
# File 'lib/shield/contrib/ohm/email_password.rb', line 32

def password
  @password
end

#password_confirmationObject

Returns the value of attribute password_confirmation.



33
34
35
# File 'lib/shield/contrib/ohm/email_password.rb', line 33

def password_confirmation
  @password_confirmation
end

Class Method Details

.included(model) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/shield/contrib/ohm/email_password.rb', line 4

def self.included(model)
  model.extend Shield::Model
  model.extend Fetch

  model.attributes << :email unless model.attributes.include?(:email)
  model.index :email

  model.attribute :crypted_password
end

Instance Method Details

#emailObject



28
29
30
# File 'lib/shield/contrib/ohm/email_password.rb', line 28

def email
  read_local(:email)
end

#email=(email) ⇒ Object



24
25
26
# File 'lib/shield/contrib/ohm/email_password.rb', line 24

def email=(email)
  write_local(:email, email.to_s.downcase.strip)
end

#validateObject



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/shield/contrib/ohm/email_password.rb', line 35

def validate
  super

  assert_present(:email) && assert_email(:email) && assert_unique(:email)

  assert_present(:password) if new?

  unless password.to_s.empty?
    assert password == password_confirmation, [:password, :not_confirmed]
  end
end