class DeclarativePolicy::Rule::Base
A Rule
is the object that results from the `rule` declaration, usually built using the DSL in `RuleDsl`. It is a basic logical combination of building blocks, and is capable of deciding, given a context (instance of DeclarativePolicy::Base
) whether it passes or not. Note that this decision doesn't by itself know how that affects the actual ability decision - for that, a `Step` is used.
Public Class Methods
# File lib/declarative_policy/rule.rb, line 13 def self.make(*args) new(*args).simplify end
Public Instance Methods
# File lib/declarative_policy/rule.rb, line 47 def and(other) And.make([self, other]) end
same as pass?
except refuses to do any I/O, returning nil if the result is not yet cached. used for accurately scoring And/Or
# File lib/declarative_policy/rule.rb, line 27 def cached_pass?(_context) raise 'abstract' end
# File lib/declarative_policy/rule.rb, line 59 def inspect "#<Rule #{repr}>" end
# File lib/declarative_policy/rule.rb, line 51 def negate Not.make(self) end
convenience combination methods
# File lib/declarative_policy/rule.rb, line 43 def or(other) Or.make([self, other]) end
true or false whether this rule passes. `context` is a policy - an instance of DeclarativePolicy::Base
.
# File lib/declarative_policy/rule.rb, line 20 def pass?(_context) raise 'abstract' end
abstractly, how long would it take to compute this rule? lower-scored rules are tried first.
# File lib/declarative_policy/rule.rb, line 33 def score(_context) raise 'abstract' end
unwrap double negatives and nested and/or
# File lib/declarative_policy/rule.rb, line 38 def simplify self end