module Challah::UserAttributeable
Public Instance Methods
name()
click to toggle source
First name and last name together
# File lib/challah/concerns/user/attributeable.rb, line 15 def name "#{ first_name } #{ last_name }".strip end
small_name()
click to toggle source
shortened name, just includes the first name and last initial
# File lib/challah/concerns/user/attributeable.rb, line 20 def small_name "#{ first_name.to_s.titleize } #{ last_name.to_s.first.upcase }." end
valid_session?()
click to toggle source
Is this user valid and ready for a user session?
Override this method if you need to check for a particular configuration on each page request.
# File lib/challah/concerns/user/attributeable.rb, line 27 def valid_session? true end
Protected Instance Methods
ensure_api_key_presence()
click to toggle source
Store a random seed for this user's api key
# File lib/challah/concerns/user/attributeable.rb, line 41 def ensure_api_key_presence if respond_to?("api_key=") if self.api_key.to_s.blank? self.api_key = Random.token(50) end end end
ensure_email_hash_presence()
click to toggle source
Store a hashed email if the column exists
# File lib/challah/concerns/user/attributeable.rb, line 50 def ensure_email_hash_presence if respond_to?("email_hash=") if email_changed? self.email_hash = generate_email_hash end end end
ensure_persistence_token_presence()
click to toggle source
Store a random token to identify user in persisted objects
# File lib/challah/concerns/user/attributeable.rb, line 59 def ensure_persistence_token_presence if respond_to?("persistence_token=") if self.persistence_token.to_s.blank? self.persistence_token = Random.token(125) end end end
ensure_user_tokens()
click to toggle source
Ensure that all system-generated columns aren't blank on each save
# File lib/challah/concerns/user/attributeable.rb, line 34 def ensure_user_tokens ensure_api_key_presence ensure_email_hash_presence ensure_persistence_token_presence end
generate_email_hash()
click to toggle source
# File lib/challah/concerns/user/attributeable.rb, line 67 def generate_email_hash if self.email.present? Encrypter.md5(email.to_s.downcase.strip) end end
normalize_user_email()
click to toggle source
Downcase email and strip if of whitespace Ex: “ HELLO@example.com ” => “hello@example.com”
# File lib/challah/concerns/user/attributeable.rb, line 75 def normalize_user_email self.email = self.email.to_s.downcase.strip end