Class: User

Inherits:
RedisModel show all
Includes:
BCrypt
Defined in:
app/models/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from RedisModel

all, #delete, delete_all, find, find_by, find_by_email, find_by_id, first, #initialize, #read_attribute_for_validation, #save, #save!, table, #table, #update

Constructor Details

This class inherits a constructor from RedisModel

Instance Attribute Details

#emailObject

Returns the value of attribute email.



3
4
5
# File 'app/models/user.rb', line 3

def email
  @email
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'app/models/user.rb', line 3

def id
  @id
end

#password_digestObject

Returns the value of attribute password_digest.



3
4
5
# File 'app/models/user.rb', line 3

def password_digest
  @password_digest
end

Instance Method Details

#authenticate(given_password) ⇒ Object



30
31
32
# File 'app/models/user.rb', line 30

def authenticate(given_password)
  password == given_password
end

#passwordObject



21
22
23
# File 'app/models/user.rb', line 21

def password
  @password ||= Password.new(password_digest)
end

#password=(new_password) ⇒ Object



25
26
27
28
# File 'app/models/user.rb', line 25

def password=(new_password)
  @password = new_password
  self.password_digest = Password.create(@password)
end

#to_hashObject



14
15
16
17
18
19
# File 'app/models/user.rb', line 14

def to_hash
  raw = {
    email: self.email,
    password_digest: password_digest
  }
end