class SwitchUser::UserLoader
Attributes
id[RW]
scope[R]
Public Class Methods
new(scope, id)
click to toggle source
# File lib/switch_user/user_loader.rb, line 21 def initialize(scope, id) self.scope = scope self.id = id end
prepare(*args)
click to toggle source
# 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
Public Instance Methods
user()
click to toggle source
# File lib/switch_user/user_loader.rb, line 26 def user user_class.where(column_name => id).first end
Private Instance Methods
column_name()
click to toggle source
# File lib/switch_user/user_loader.rb, line 44 def column_name SwitchUser.available_users_identifiers[scope.to_sym] end
scope=(scope)
click to toggle source
# File lib/switch_user/user_loader.rb, line 32 def scope=(scope) if scope && SwitchUser.available_scopes.include?(scope.to_sym) @scope = scope else raise InvalidScope, "#{scope} is invalid and is not listed in SwitchUser#available_users" end end
user_class()
click to toggle source
# File lib/switch_user/user_loader.rb, line 40 def user_class scope.classify.constantize end