Class: DeviseRemoteUser::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/devise_remote_user/manager.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, env) ⇒ Manager

Returns a new instance of Manager.



11
12
13
14
# File 'lib/devise_remote_user/manager.rb', line 11

def initialize(klass, env)
  @klass = klass
  @env = env
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



9
10
11
# File 'lib/devise_remote_user/manager.rb', line 9

def env
  @env
end

#klassObject (readonly)

Returns the value of attribute klass.



9
10
11
# File 'lib/devise_remote_user/manager.rb', line 9

def klass
  @klass
end

Instance Method Details

#create_userObject



29
30
31
32
33
# File 'lib/devise_remote_user/manager.rb', line 29

def create_user
  random_password = SecureRandom.hex(16)
  attrs = user_criterion.merge({password: random_password, password_confirmation: random_password})
  klass.create(attrs)
end

#find_or_create_userObject



16
17
18
19
20
21
22
23
# 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_userObject



25
26
27
# File 'lib/devise_remote_user/manager.rb', line 25

def find_user
  klass.where(user_criterion).first
end

#update_user(user) ⇒ Object



35
36
37
# File 'lib/devise_remote_user/manager.rb', line 35

def update_user(user)
  user.update_attributes(remote_user_attributes)
end