Class: ActiveAdmin::PunditAdapter
  
  
  
  Instance Attribute Summary
  
  
  #resource, #user
  
    
      Instance Method Summary
      collapse
    
    
  
  
  
  
  
  
  
  
  
  
  #initialize
  
    Instance Method Details
    
      
  
  
    #authorized?(action, subject = nil)  ⇒ Boolean 
  
  
  
  
    
      
14
15
16
17
18
19 
     | 
    
      # File 'lib/active_admin/pundit_adapter.rb', line 14
def authorized?(action, subject = nil)
  policy = retrieve_policy(subject)
  action = format_action(action, subject)
  policy.respond_to?(action) && policy.public_send(action)
end 
     | 
  
 
    
      
  
  
    
      
44
45
46
47
48
49
50
51 
     | 
    
      # File 'lib/active_admin/pundit_adapter.rb', line 44
def format_action(action, subject)
    case action
  when Auth::READ then subject.is_a?(Class) ? :index? : :show?
  when Auth::DESTROY then subject.is_a?(Class) ? :destroy_all? : :destroy?
  else "#{action}?"
  end
end
     | 
  
 
    
      
  
  
    #retrieve_policy(subject)  ⇒ Object 
  
  
  
  
    
      
33
34
35
36
37
38
39
40
41
42 
     | 
    
      # File 'lib/active_admin/pundit_adapter.rb', line 33
def retrieve_policy(subject)
  target = policy_target(subject)
  if (policy = policy(namespace(target)) || compat_policy(subject))
    policy
  elsif default_policy_class
    default_policy(subject)
  else
    raise Pundit::NotDefinedError, "unable to find a compatible policy for `#{target}`"
  end
end
     | 
  
 
    
      
  
  
    #scope_collection(collection, action = Auth::READ)  ⇒ Object 
  
  
  
  
    
      
21
22
23
24
25
26
27
28
29
30
31 
     | 
    
      # File 'lib/active_admin/pundit_adapter.rb', line 21
def scope_collection(collection, action = Auth::READ)
      Pundit.policy_scope!(user, namespace(collection))
rescue Pundit::NotDefinedError => e
  if default_policy_class && default_policy_class.const_defined?(:Scope)
    default_policy_class::Scope.new(user, collection).resolve
  else
    raise e
  end
end
     |