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.



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

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

Instance Attribute Details

#idObject

Returns the value of attribute id.



6
7
8
# File 'lib/switch_user/user_loader.rb', line 6

def id
  @id
end

#scopeObject

Returns the value of attribute scope.



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

def scope
  @scope
end

Class Method Details

.prepare(*args) ⇒ Object



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

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

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

Instance Method Details

#userObject



26
27
28
# File 'lib/switch_user/user_loader.rb', line 26

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