class SwitchUser::Provider::Base

Public Instance Methods

clear_original_user() click to toggle source
# File lib/switch_user/provider/base.rb, line 55
def clear_original_user
  @controller.session.delete(:original_user_scope_identifier)
end
current_user?(user, scope = :user) click to toggle source
# File lib/switch_user/provider/base.rb, line 59
def current_user?(user, scope = :user)
  current_user(scope) == user
end
current_users_without_scope() click to toggle source
# File lib/switch_user/provider/base.rb, line 6
def current_users_without_scope
  SwitchUser.available_scopes.each_with_object([]) do |scope, users|
    user = current_user(scope)
    users << user if user
  end
end
login_exclusive(user, args) click to toggle source
# File lib/switch_user/provider/base.rb, line 13
def login_exclusive(user, args)
  requested_scope = args.fetch(:scope, :user).to_sym

  logout_all
  login(user, requested_scope)
end
login_inclusive(user, args) click to toggle source
# File lib/switch_user/provider/base.rb, line 20
def login_inclusive(user, args)
  requested_scope = args.fetch(:scope, :user).to_sym

  logout(requested_scope)
  login(user, requested_scope)
end
logout_all() click to toggle source
# File lib/switch_user/provider/base.rb, line 27
def logout_all
  SwitchUser.available_scopes.each do |scope|
    logout(scope)
  end
end
original_user() click to toggle source
# File lib/switch_user/provider/base.rb, line 33
def original_user
  user_identifier = @controller.session[:original_user_scope_identifier]

  UserLoader.prepare(scope_identifier: user_identifier).user if user_identifier
end
original_user=(user) click to toggle source
# File lib/switch_user/provider/base.rb, line 39
def original_user=(user)
  user_type = user.class.to_s.underscore
  column_name = SwitchUser.available_users_identifiers[user_type.to_sym]
  user_identifier = "#{user_type}_#{user.send(column_name)}"

  @controller.session[:original_user_scope_identifier] = user_identifier
end
remember_current_user(remember) click to toggle source
# File lib/switch_user/provider/base.rb, line 47
def remember_current_user(remember)
  if remember
    self.original_user = current_user
  else
    clear_original_user
  end
end