Class: SwitchUser::Provider::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/switch_user/provider/base.rb

Instance Method Summary collapse

Instance Method Details

#clear_original_userObject



44
45
46
# File 'lib/switch_user/provider/base.rb', line 44

def clear_original_user
  @controller.session.delete(:original_user)
end

#current_users_without_scopeObject



4
5
6
7
8
9
10
# File 'lib/switch_user/provider/base.rb', line 4

def current_users_without_scope
  SwitchUser.available_scopes.inject([]) do |users, scope|
    user = current_user(scope)
    users << user if user
    users
  end
end

#login_exclusive(user, args) ⇒ Object



12
13
14
15
16
17
# File 'lib/switch_user/provider/base.rb', line 12

def (user, args)
  requested_scope = args.fetch(:scope, :user).to_sym

  logout_all
  (user, requested_scope)
end

#login_inclusive(user, args) ⇒ Object



19
20
21
22
23
24
# File 'lib/switch_user/provider/base.rb', line 19

def (user, args)
  requested_scope = args.fetch(:scope, :user).to_sym

  logout(requested_scope)
  (user, requested_scope)
end

#logout_allObject



26
27
28
29
30
# File 'lib/switch_user/provider/base.rb', line 26

def logout_all
  SwitchUser.available_scopes.each do |scope|
    logout(scope)
  end
end

#original_userObject



32
33
34
# File 'lib/switch_user/provider/base.rb', line 32

def original_user
  @controller.session[:original_user]
end

#remember_current_user(remember) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/switch_user/provider/base.rb', line 36

def remember_current_user(remember)
  if remember
    @controller.session[:original_user] = current_user
  else
    @controller.session.delete(:original_user)
  end
end