Module: SwitchUser

Defined in:
lib/switch_user.rb,
lib/switch_user/rails.rb,
lib/switch_user/version.rb,
lib/switch_user/provider.rb,
lib/switch_user/user_set.rb,
lib/switch_user/base_guard.rb,
lib/switch_user/data_source.rb,
lib/switch_user/user_loader.rb,
lib/switch_user/lambda_guard.rb,
lib/switch_user/provider/base.rb,
lib/switch_user/provider/dummy.rb,
lib/switch_user/provider/devise.rb,
lib/switch_user/provider/session.rb,
lib/switch_user/provider/sorcery.rb,
lib/switch_user/provider/authlogic.rb,
lib/switch_user/provider/clearance.rb,
lib/switch_user/rspec/feature_helpers.rb,
lib/switch_user/provider/restful_authentication.rb,
lib/generators/switch_user/install/install_generator.rb

Defined Under Namespace

Modules: Generators, Provider, RSpecFeatureHelpers Classes: BaseGuard, DataSource, DataSources, Engine, GuestDataSource, GuestRecord, InvalidScope, LambdaGuard, Record, UserLoader, UserSet

Constant Summary collapse

VERSION =
'1.5.4'

Class Method Summary collapse

Class Method Details

.all_usersObject



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

def self.all_users
  data_sources.all
end

.available_scopesObject



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

def self.available_scopes
  available_users.keys
end

.data_sourcesObject



44
45
46
47
48
49
50
51
52
53
# File 'lib/switch_user.rb', line 44

def self.data_sources
  sources =
    available_users.map do |scope, loader|
      identifier = available_users_identifiers.fetch(scope)
      name = available_users_names.fetch(scope)
      DataSource.new(loader, scope, identifier, name)
    end
  sources.unshift(GuestDataSource.new) if helper_with_guest
  DataSources.new(sources)
end

.guard_class=(klass) ⇒ Object



36
37
38
# File 'lib/switch_user.rb', line 36

def self.guard_class=(klass)
  @@guard_class = klass.constantize
end

.reset_configObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/switch_user.rb', line 55

def self.reset_config
  self.provider = :devise
  self.available_users = { user: -> { User.all } }
  self.available_users_identifiers = { user: :id }
  self.available_users_names = { user: :email }
  self.guard_class = 'SwitchUser::LambdaGuard'
  self.controller_guard = ->(_current_user, _request) { Rails.env.development? }
  self.view_guard = ->(_current_user, _request) { Rails.env.development? }
  self.redirect_path = ->(request, _params) { request.env['HTTP_REFERER'] ? :back : root_path }
  self.session_key = :user_id
  self.helper_with_guest = true
  self.switch_back = false
  self. = true
end

.setup {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (SwitchUser)

    the object that the method was called on



28
29
30
# File 'lib/switch_user.rb', line 28

def self.setup
  yield self
end