Class: SwitchUser::UserLoader

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(scope, id) ⇒ UserLoader

Returns a new instance of UserLoader.



18
19
20
21
# File 'lib/switch_user/user_loader.rb', line 18

def initialize(scope, id)
  self.scope = scope
  self.id = id
end

Instance Attribute Details

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/switch_user/user_loader.rb', line 4

def id
  @id
end

#scopeObject

Returns the value of attribute scope.



3
4
5
# File 'lib/switch_user/user_loader.rb', line 3

def scope
  @scope
end

Class Method Details

.prepare(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/switch_user/user_loader.rb', line 6

def self.prepare(*args)
  options = args.extract_options!

  if options[:scope_identifier]
    options[:scope_identifier] =~ /^(.*)_([^_]+)$/
    scope, id = $1, $2
  else
    scope, id = args
  end
  new(scope, id)
end

Instance Method Details

#userObject



23
24
25
# File 'lib/switch_user/user_loader.rb', line 23

def user
  user_class.where(column_name => id).first
end