Module: CanTango::Api::Masquerade::User

Defined in:
lib/cantango/masquerade/api/masquerade/user.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#active_userObject (readonly)

Returns the value of attribute active_user.



3
4
5
# File 'lib/cantango/masquerade/api/masquerade/user.rb', line 3

def active_user
  @active_user
end

#masqueradingObject (readonly)

Returns the value of attribute masquerading.



3
4
5
# File 'lib/cantango/masquerade/api/masquerade/user.rb', line 3

def masquerading
  @masquerading
end

Instance Method Details

#masquerade_as(user) ⇒ Object



5
6
7
8
9
10
# File 'lib/cantango/masquerade/api/masquerade/user.rb', line 5

def masquerade_as user
  raise "Must be a registered type of user, was: #{user}" unless valid_user? user
  @masquerading = true
  user = user.kind_of?(String) ? ::User.find(user) : user
  @active_user = user
end

#masquerading?Boolean Also known as: masquerade?

Returns:

  • (Boolean)


16
17
18
# File 'lib/cantango/masquerade/api/masquerade/user.rb', line 16

def masquerading?
  !@masquerading.nil?
end

#stop_masqueradeObject



12
13
14
# File 'lib/cantango/masquerade/api/masquerade/user.rb', line 12

def stop_masquerade
  @active_user, @masquerading = nil, nil
end