Class: User
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- User
- Defined in:
- app/models/user.rb
Class Method Summary collapse
-
.anonymous(attributes = {}) ⇒ Object
FIXME rename to build_anonymous.
- .authenticate(credentials) ⇒ Object
Instance Method Summary collapse
- #attributes=(attributes) ⇒ Object
- #email_with_name ⇒ Object
- #first_name_from_email ⇒ Object
- #homepage ⇒ Object
- #member_of?(site) ⇒ Boolean
- #name ⇒ Object
- #name=(name) ⇒ Object
-
#registered? ⇒ Boolean
def restore! update deleted_at: nil if deleted_at end.
- #to_s ⇒ Object
- #update_memberships(memberships) ⇒ Object
- #verified? ⇒ Boolean
- #verify! ⇒ Object
Class Method Details
.anonymous(attributes = {}) ⇒ Object
FIXME rename to build_anonymous
29 30 31 32 |
# File 'app/models/user.rb', line 29 def anonymous(attributes = {}) # FIXME rename to build_anonymous attributes[:anonymous] = true new attributes end |
.authenticate(credentials) ⇒ Object
24 25 26 27 |
# File 'app/models/user.rb', line 24 def authenticate(credentials) return false unless user = User.find_by_email(credentials[:email]) user.authenticate(credentials[:password]) ? user : false end |
Instance Method Details
#attributes=(attributes) ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/models/user.rb', line 35 def attributes=(attributes) attributes.symbolize_keys! memberships = attributes.delete :memberships super.tap do update_memberships memberships if memberships end end |
#email_with_name ⇒ Object
86 87 88 |
# File 'app/models/user.rb', line 86 def email_with_name "#{name} <#{email}>" end |
#first_name_from_email ⇒ Object
96 97 98 |
# File 'app/models/user.rb', line 96 def first_name_from_email self.first_name.blank? && self.email ? self.email.split('@').first : self.first_name end |
#homepage ⇒ Object
90 91 92 93 94 |
# File 'app/models/user.rb', line 90 def homepage return nil unless self[:homepage] self[:homepage][0..6] == 'http://' ? self[:homepage] : 'http://' + self[:homepage] end |
#member_of?(site) ⇒ Boolean
54 55 56 |
# File 'app/models/user.rb', line 54 def member_of?(site) sites.include?(site) end |
#name ⇒ Object
78 79 80 |
# File 'app/models/user.rb', line 78 def name last_name ? "#{first_name} #{last_name}" : first_name end |
#name=(name) ⇒ Object
74 75 76 |
# File 'app/models/user.rb', line 74 def name=(name) self.first_name = name end |
#registered? ⇒ Boolean
def restore!
update deleted_at: nil if deleted_at
end
70 71 72 |
# File 'app/models/user.rb', line 70 def registered? !new_record? && !anonymous? end |
#to_s ⇒ Object
82 83 84 |
# File 'app/models/user.rb', line 82 def to_s name end |
#update_memberships(memberships) ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'app/models/user.rb', line 43 def update_memberships(memberships) memberships.each do |site_id, active| site = Site.find(site_id) if active self.sites << site unless member_of?(site) else self.sites.delete(site) if member_of?(site) end end end |
#verified? ⇒ Boolean
58 59 60 |
# File 'app/models/user.rb', line 58 def verified? !verified_at.nil? end |
#verify! ⇒ Object
62 63 64 |
# File 'app/models/user.rb', line 62 def verify! update verified_at: Time.zone.now if verified_at.nil? end |