Commit 98d99c5e authored by Sean Arnold's avatar Sean Arnold Committed by Dmitriy Zaporozhets

Add declarative_policy_class to Declarative Policy

parent 41049688
...@@ -157,3 +157,18 @@ end ...@@ -157,3 +157,18 @@ end
``` ```
will include all rules from `ProjectPolicy`. The delegated conditions will be evaluated with the correct delegated subject, and will be sorted along with the regular rules in the policy. Note that only the relevant rules for a particular ability will actually be considered. will include all rules from `ProjectPolicy`. The delegated conditions will be evaluated with the correct delegated subject, and will be sorted along with the regular rules in the policy. Note that only the relevant rules for a particular ability will actually be considered.
## Specifying Policy Class
You can also override the Policy used for a given subject:
```ruby
class Foo
def self.declarative_policy_class
'SomeOtherPolicy'
end
end
```
This will use & check permissions on the `SomeOtherPolicy` class rather than the usual calculated `FooPolicy` class.
...@@ -74,7 +74,14 @@ module DeclarativePolicy ...@@ -74,7 +74,14 @@ module DeclarativePolicy
next unless klass.name next unless klass.name
begin begin
policy_class = "#{klass.name}Policy".constantize klass_name =
if subject_class.respond_to?(:declarative_policy_class)
subject_class.declarative_policy_class
else
"#{klass.name}Policy"
end
policy_class = klass_name.constantize
# NOTE: the < operator here tests whether policy_class # NOTE: the < operator here tests whether policy_class
# inherits from Base. We can't use #is_a? because that # inherits from Base. We can't use #is_a? because that
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment