Skip to content

Latest commit

 

History

History
22 lines (13 loc) · 1.13 KB

lookup_chain.md

File metadata and controls

22 lines (13 loc) · 1.13 KB

Policy Lookup

Action Policy tries to automatically infer policy class from the target using the following probes:

  1. If the target is a Symbol:

    a) Try "#{target.to_s.camelize}Policy" as a policy_name (see below);

    b) If String#classify is available, e.g. when using Rails' ActiveSupport, try "#{target.to_s.classify}Policy";

  2. If the target responds to policy_class, then use it;

  3. If the target's class responds to policy_class, then use it;

  4. If the target or the target's class responds to policy_name, then use it (the policy_name should end with Policy as it's not appended automatically);

  5. Otherwise, use #{target.class.name}Policy or #{target.name}Policy if target is a Module or Class.

* Namespaces could be also be considered when namespace option is set. You can also set the strict_namespace option to disable constant cascade lookup.

You can call ActionPolicy.lookup(record, options) to infer policy class for the record.

When no policy class is found, an ActionPolicy::NotFound error is raised.

You can customize lookup logic if necessary.