Policy Lookup
Action Policy tries to automatically infer policy class from the target using the following probes:
If the target is a
Symbol:a) Try
"#{target.to_s.camelize}Policy"as apolicy_name(see below);b) If
String#classifyis available, e.g. when using Rails' ActiveSupport, try"#{target.to_s.classify}Policy";If the target responds to
policy_class, then use it;If the target's class responds to
policy_class, then use it;If the target or the target's class responds to
policy_name, then use it (thepolicy_nameshould end withPolicyas it's not appended automatically);Otherwise, use
#{target.class.name}Policyor#{target.name}Policyif target is a Module or Class.
* Namespaces could be also be considered when
namespaceoption is set. You can also set thestrict_namespaceoption 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.