Module: UserExtensions
- Extended by:
- ActiveSupport::Concern
- Included in:
- Lesli::User
- Defined in:
- app/models/concerns/user_extensions.rb
Overview
User extension methods Custom methods that belongs to a instance user
Instance Method Summary collapse
-
#calendar(source_code: :lesli) ⇒ CloudDriver::Calendar
If source_code is provided the method return the specified source calendar.
-
#full_name ⇒ String
The name of this user.
-
#full_name_initials ⇒ String
The name initials of this user.
-
#locale ⇒ String
of the platform will be returned.
-
#mfa_settings ⇒ void
Example user_mfa_settings = User.find(2).mfa_settings puts user_mfa_settings { :mfa_enabled => true, :mfa_method => “email”}.
-
#name2 ⇒ String
The first name of this user.
- #notification(subject, body: nil, url: nil, category: "info") ⇒ void
- #set_alias ⇒ nil
Instance Method Details
#calendar(source_code: :lesli) ⇒ CloudDriver::Calendar
If source_code is provided the method return the specified source calendar.
54 55 56 57 |
# File 'app/models/concerns/user_extensions.rb', line 54 def calendar source_code: :lesli return Courier::Driver::Calendar.get_user_calendar(self, source_code: source_code, default: true) if source_code == :lesli Courier::Driver::Calendar.get_user_calendar(self, source_code: source_code) end |
#full_name ⇒ String
Returns The name of this user.
76 77 78 |
# File 'app/models/concerns/user_extensions.rb', line 76 def full_name self.first_name.blank? ? email : self.first_name + " " + self.last_name.to_s end |
#full_name_initials ⇒ String
Returns The name initials of this user.
85 86 87 |
# File 'app/models/concerns/user_extensions.rb', line 85 def full_name_initials self.first_name.blank? ? "" : self.first_name[0].upcase + "" + (self.last_name.blank? ? "" : self.last_name[0].upcase) end |
#locale ⇒ String
of the platform will be returned
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'app/models/concerns/user_extensions.rb', line 109 def locale user_locale = self.settings.find_by(name: "locale") # return the desire locale by the user return user_locale.value.to_sym if user_locale # create a desire locale if the record does not exist self.settings.create_with(:value => I18n.locale).find_or_create_by(:name => "locale") # reevaluate self.locale() end |
#mfa_settings ⇒ void
This method returns an undefined value.
Example
user_mfa_settings = User.find(2).mfa_settings
puts user_mfa_settings
{ :mfa_enabled => true, :mfa_method => "email"}
129 130 131 132 133 134 135 136 |
# File 'app/models/concerns/user_extensions.rb', line 129 def mfa_settings mfa_enabled = self.settings.create_with(:value => false).find_or_create_by(:name => "mfa_enabled") mfa_method = self.settings.create_with(:value => :email).find_or_create_by(:name => "mfa_method") { :enabled => mfa_enabled.nil? ? false : mfa_enabled.value == 't', :method => mfa_method.nil? ? nil : mfa_method.value.to_sym } end |
#name2 ⇒ String
Returns The first name of this user.
61 62 63 |
# File 'app/models/concerns/user_extensions.rb', line 61 def name2 self.first_name end |
#notification(subject, body: nil, url: nil, category: "info") ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'app/models/concerns/user_extensions.rb', line 46 def notification subject, body:nil, url:nil, category:"info" Courier::Bell::Notification.new(self, subject, body:body, url:url, category:category) end |
#set_alias ⇒ nil
95 96 97 98 99 100 |
# File 'app/models/concerns/user_extensions.rb', line 95 def set_alias if self.alias.blank? self.alias = full_name_initials() self.save end end |