Class: User

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Houston::Props, Retirement
Defined in:
app/models/user.rb

Constant Summary collapse

ROLES =
%w{Owner Admin Member}.freeze

Constants included from Houston::Props

Houston::Props::VALID_PROP_NAME

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Houston::Props

#get_prop, #props, #update_prop!, #update_props!, valid_prop_name!, valid_prop_name?

Methods included from Retirement

#retire!, #retired?, #unretire!

Class Method Details

.find_by_email_address(email_address) ⇒ Object



57
58
59
# File 'app/models/user.rb', line 57

def self.find_by_email_address(email_address)
  with_email_address(email_address).first
end

.with_email_address(*email_addresses) ⇒ Object



51
52
53
54
55
# File 'app/models/user.rb', line 51

def self.with_email_address(*email_addresses)
  email_addresses = email_addresses.flatten.compact
  return none if email_addresses.none?
  where ["email_addresses && ARRAY[?]", email_addresses.map(&:downcase)]
end

.with_primary_email(email) ⇒ Object



46
47
48
49
# File 'app/models/user.rb', line 46

def self.with_primary_email(email)
  email = email.downcase if email
  where(email: email)
end

Instance Method Details

#alias_emailsObject



71
72
73
# File 'app/models/user.rb', line 71

def alias_emails
  email_addresses - [email]
end

#alias_emails=(value) ⇒ Object



75
76
77
# File 'app/models/user.rb', line 75

def alias_emails=(value)
  self.email_addresses = [email] + Array.wrap(value).reject(&:blank?)
end

#email=(value) ⇒ Object



61
62
63
64
65
# File 'app/models/user.rb', line 61

def email=(value)
  value = value.downcase if value
  super(value)
  self.email_addresses = [email] + alias_emails
end

#email_addressesObject



67
68
69
# File 'app/models/user.rb', line 67

def email_addresses
  (super || []).reject(&:blank?)
end

#follow!(project) ⇒ Object



87
88
89
# File 'app/models/user.rb', line 87

def follow!(project)
  followed_projects << project
end

#follows?(project) ⇒ Boolean

Returns:

  • (Boolean)


95
96
97
# File 'app/models/user.rb', line 95

def follows?(project)
  followed_projects.member?(project)
end

#nameObject



81
82
83
# File 'app/models/user.rb', line 81

def name
  "#{first_name} #{last_name}"
end

#unfollow!(project) ⇒ Object



91
92
93
# File 'app/models/user.rb', line 91

def unfollow!(project)
  followed_projects.delete project
end