Module: Pageflow::UserMixin

Extended by:
ActiveSupport::Concern
Includes:
Suspendable
Defined in:
lib/pageflow/user_mixin.rb

Overview

ActiveRecord related functionality of the Pageflow users.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Methods included from Suspendable

#active_for_authentication?, #suspend!, #suspended?, #unsuspend!

Instance Method Details

#admin?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/pageflow/user_mixin.rb', line 44

def admin?
  admin
end

#destroy_with_password(password) ⇒ Object



70
71
72
73
74
75
76
77
78
# File 'lib/pageflow/user_mixin.rb', line 70

def destroy_with_password(password)
  if valid_password?(password)
    destroy
    true
  else
    errors.add(:current_password, password.blank? ? :blank : :invalid)
    false
  end
end

#ensure_unread_comments_since_atObject

Comments predating a user are not new to them. Without a baseline, joining would mean facing every comment ever written as unread.



40
41
42
# File 'lib/pageflow/user_mixin.rb', line 40

def ensure_unread_comments_since_at
  self.unread_comments_since_at ||= Time.current
end

#formal_nameObject



52
53
54
# File 'lib/pageflow/user_mixin.rb', line 52

def formal_name
  [last_name, first_name].join(', ')
end

#full_nameObject



48
49
50
# File 'lib/pageflow/user_mixin.rb', line 48

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

#localeObject



56
57
58
# File 'lib/pageflow/user_mixin.rb', line 56

def locale
  super.presence || I18n.default_locale.to_s
end

#send_devise_notification(notification) ⇒ Object

Configure devise to send emails using ActiveJob.



81
82
83
# File 'lib/pageflow/user_mixin.rb', line 81

def send_devise_notification(notification, *)
  devise_mailer.send(notification, self, *).deliver_later
end

#update_with_password(attributes) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/pageflow/user_mixin.rb', line 60

def update_with_password(attributes)
  if needs_password?(attributes)
    super
  else
    # remove the virtual current_password attribute update_without_password
    # doesn't know how to ignore it
    update_without_password(attributes.except(:current_password))
  end
end