Class: Stay::User

Inherits:
ApplicationRecord show all
Defined in:
app/models/stay/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#updating_passwordObject

Returns the value of attribute updating_password.



43
44
45
# File 'app/models/stay/user.rb', line 43

def updating_password
  @updating_password
end

Class Method Details

.admin_emailsObject



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

def self.admin_emails
  joins(:stay_roles).where(stay_roles: { name: Stay::Role::ADMIN }).pluck(:email).uniq
end

.ransackable_associations(auth_object = nil) ⇒ Object



49
50
51
# File 'app/models/stay/user.rb', line 49

def self.ransackable_associations(auth_object = nil)
  %w[stay_roles bookings]
end

.ransackable_attributes(auth_object = nil) ⇒ Object



45
46
47
# File 'app/models/stay/user.rb', line 45

def self.ransackable_attributes(auth_object = nil)
  %w[email first_name last_name]
end

Instance Method Details

#full_nameObject



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

def full_name
  [ first_name, last_name ].compact.join(" ")
end

#has_stay_role?(role_name) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_stay_role?(role_name)
  stay_roles.exists?(name: role_name)
end

#nameObject



77
78
79
# File 'app/models/stay/user.rb', line 77

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

#password_required?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'app/models/stay/user.rb', line 85

def password_required?
  updating_password || super
end

#rolesObject



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

def roles
  stay_roles
end

#set_default_preferencesObject



89
90
91
92
# File 'app/models/stay/user.rb', line 89

def set_default_preferences
  self.whatsapp_notification = true if whatsapp_notification.nil?
  self.sms_notification = false if sms_notification.nil?
end

#stay_admin?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'app/models/stay/user.rb', line 65

def stay_admin?
  has_stay_role?(Stay::Role::ADMIN)
end

#stay_host?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'app/models/stay/user.rb', line 69

def stay_host?
  has_stay_role?(Stay::Role::HOST)
end

#stay_user?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'app/models/stay/user.rb', line 73

def stay_user?
  has_stay_role?(Stay::Role::USER)
end