class DeviseRemoteUser::Manager

The Manager class is responsible for connecting the appliation's User class with remote user information in the request environment.

Attributes

env[R]
klass[R]

Public Class Methods

new(klass, env) click to toggle source
# File lib/devise_remote_user/manager.rb, line 11
def initialize(klass, env)
  @klass = klass
  @env = env
end

Public Instance Methods

create_user() click to toggle source
# File lib/devise_remote_user/manager.rb, line 29
def create_user
  unless Devise.mappings[:user].strategies.include?(:database_authenticatable)
    return klass.create(user_criterion)
  end

  random_password = SecureRandom.hex(16)
  attrs = user_criterion.merge({password: random_password, password_confirmation: random_password})
  klass.create(attrs)
end
find_or_create_user() click to toggle source
# File lib/devise_remote_user/manager.rb, line 16
def find_or_create_user
  user = find_user
  if !user && DeviseRemoteUser.auto_create
    user = create_user
  end
  update_user(user) if user && DeviseRemoteUser.auto_update
  user
end
find_user() click to toggle source
# File lib/devise_remote_user/manager.rb, line 25
def find_user
  klass.where(user_criterion).first
end
update_user(user) click to toggle source
# File lib/devise_remote_user/manager.rb, line 39
def update_user(user)
  user.update(remote_user_attributes)
end

Protected Instance Methods

auth_key() click to toggle source
# File lib/devise_remote_user/manager.rb, line 57
def auth_key
  DeviseRemoteUser.auth_key || Devise.authentication_keys.first
end
remote_user_attributes() click to toggle source
# File lib/devise_remote_user/manager.rb, line 45
def remote_user_attributes
  DeviseRemoteUser.attribute_map.inject({}) { |h, (k, v)| h[k] = env[v] if env.has_key?(v); h }
end
remote_user_id() click to toggle source
# File lib/devise_remote_user/manager.rb, line 53
def remote_user_id
  DeviseRemoteUser.remote_user_id(env)
end
user_criterion() click to toggle source
# File lib/devise_remote_user/manager.rb, line 49
def user_criterion
  {auth_key => remote_user_id}
end