Module: CoreUser

Extended by:
ActiveSupport::Concern
Defined in:
lib/app/models/concerns/core_user.rb

Overview

The Base User

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/app/models/concerns/core_user.rb', line 9

def self.included(base)
  base.class_eval do
    # Fields
    field :name, type: String
    field :avatar, type: String, default: '1'
    field :theme, type: String, default: 'default'
    field :style, type: String, default: 'light'
    field :color, type: String, default: '#0D9394'


    # @abstract Return the display name for the user
    # 1. If :name is blank, then just return the email
    # 2. If :name is NOT blank, then use "Name (email)"
    # @return [String] - the name of the user
    def display_name
      name.blank? ? email : "#{name} (#{email})"
    end

    # @abstract the initials for the user
    # @return [String]
    def initials
      if name.blank?
        [email[0], email[1]].join
      else
        name.split.map { |n| n.first.upcase }.join
      end
    end
  end
end