Class: Renalware::User

Inherits:
ApplicationRecord show all
Includes:
Deviseable, Personable
Defined in:
app/models/renalware/user.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#with_extended_validationObject

Non-persistent attribute to signify we want to use extended validation. We need to refactor this by ising a form object for updating a user.



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

def with_extended_validation
  @with_extended_validation
end

Class Method Details

.policy_classObject



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

def self.policy_class
  UserPolicy
end

.ransackable_scopes(_auth_object = nil) ⇒ Object

So we can uses these scopes as Ransack predicates eg. { expired: true }



50
51
52
# File 'app/models/renalware/user.rb', line 50

def self.ransackable_scopes(_auth_object = nil)
  %i(unapproved inactive expired)
end

Instance Method Details

#generate_new_authentication_token!Object



72
73
74
75
76
# File 'app/models/renalware/user.rb', line 72

def generate_new_authentication_token!
  build_authentication_token.tap do |token|
    update_column(:authentication_token, token)
  end
end

#has_role?(name) ⇒ Boolean

rubocop:disable Naming/PredicateName

Returns:

  • (Boolean)


55
56
57
# File 'app/models/renalware/user.rb', line 55

def has_role?(name)
  role_names.include?(name.to_s)
end

#professional_signatureObject

Official name for use when displaying e.g. on a letter. For example:

Dr Isaac Newton (Consultant Gravitationalist)


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

def professional_signature
  signed = signature || full_name
  signed += " (#{professional_position})" if professional_position?
  signed
end

#role_namesObject

rubocop:enable Naming/PredicateName



60
61
62
# File 'app/models/renalware/user.rb', line 60

def role_names
  @role_names ||= roles.pluck(:name)
end