Class: User
- Inherits:
-
ApplicationRecord
- Object
- ApplicationRecord
- User
- Defined in:
- lib/generators/rockstart/authorization/devise/templates/models/user.rb
Overview
User model used to represent registered User
Instance Method Summary collapse
-
#active_for_authentication? ⇒ Boolean
- devise
-
ensure user account is active.
-
#first_name ⇒ Object
Short display name for user.
-
#image ⇒ Object
Display image for user.
-
#inactive_message ⇒ Object
- devise
-
provide a custom message for a soft-deleted account.
-
#soft_delete ⇒ Object
instead of deleting users, mark them as soft deleted.
- #to_s ⇒ Object
Instance Method Details
#active_for_authentication? ⇒ Boolean
- devise
-
ensure user account is active
35 36 37 |
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 35 def active_for_authentication? super && !deleted_at? end |
#first_name ⇒ Object
Short display name for user
16 17 18 |
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 16 def first_name namae.given end |
#image ⇒ Object
Display image for user
21 22 23 24 25 26 27 |
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 21 def image return unless email? require "digest/md5" hash = Digest::MD5.hexdigest(email.downcase) "https://s.gravatar.com/avatar/#{hash}?s=480" end |
#inactive_message ⇒ Object
- devise
-
provide a custom message for a soft-deleted account
40 41 42 |
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 40 def !deleted_at? ? super : :deleted_account end |
#soft_delete ⇒ Object
instead of deleting users, mark them as soft deleted
30 31 32 |
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 30 def soft_delete update_attribute(:deleted_at, Time.current) end |
#to_s ⇒ Object
44 45 46 47 |
# File 'lib/generators/rockstart/authorization/devise/templates/models/user.rb', line 44 def to_s # Use the stored name value for labels (name_changed? ? name_was : name) || super end |