Class: LcpRuby::ImpersonatedUser

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/lcp_ruby/authorization/impersonated_user.rb

Instance Method Summary collapse

Constructor Details

#initialize(real_user, impersonated_role) ⇒ ImpersonatedUser

Returns a new instance of ImpersonatedUser.



5
6
7
8
# File 'lib/lcp_ruby/authorization/impersonated_user.rb', line 5

def initialize(real_user, impersonated_role)
  super(real_user)
  @impersonated_role = impersonated_role
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

Override role method to return impersonated role. Override group method to return [] — impersonation suppresses group-derived roles. Handles both the default methods and any custom role_method/group_method.



13
14
15
16
17
18
19
20
21
# File 'lib/lcp_ruby/authorization/impersonated_user.rb', line 13

def method_missing(method_name, *args, &block)
  if method_name == LcpRuby.configuration.role_method
    [ @impersonated_role ]
  elsif method_name == LcpRuby.configuration.group_method
    []
  else
    super
  end
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
# File 'lib/lcp_ruby/authorization/impersonated_user.rb', line 23

def respond_to_missing?(method_name, include_private = false)
  method_name == LcpRuby.configuration.role_method ||
    method_name == LcpRuby.configuration.group_method ||
    super
end