Class: DeviseRemoteUser::Manager
- Inherits:
-
Object
- Object
- DeviseRemoteUser::Manager
- 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
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
- #create_user ⇒ Object
- #find_or_create_user ⇒ Object
- #find_user ⇒ Object
-
#initialize(klass, env) ⇒ Manager
constructor
A new instance of Manager.
- #update_user(user) ⇒ Object
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
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/devise_remote_user/manager.rb', line 9 def env @env end |
#klass ⇒ Object (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_user ⇒ Object
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_user ⇒ Object
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_user ⇒ Object
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 |