Class: DeclarativePolicy::Rule::Base
- Inherits:
-
Object
- Object
- DeclarativePolicy::Rule::Base
- Defined in:
- lib/declarative_policy/rule.rb
Overview
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.
Class Method Summary collapse
Instance Method Summary collapse
- #and(other) ⇒ Object (also: #&)
-
#cached_pass?(_context) ⇒ Boolean
same as #pass? except refuses to do any I/O, returning nil if the result is not yet cached.
- #inspect ⇒ Object
- #negate ⇒ Object (also: #~)
-
#or(other) ⇒ Object
(also: #|)
convenience combination methods.
-
#pass?(_context) ⇒ Boolean
true or false whether this rule passes.
-
#score(_context) ⇒ Object
abstractly, how long would it take to compute this rule? lower-scored rules are tried first.
-
#simplify ⇒ Object
unwrap double negatives and nested and/or.
Class Method Details
.make(*args) ⇒ Object
13 14 15 |
# File 'lib/declarative_policy/rule.rb', line 13 def self.make(*args) new(*args).simplify end |
Instance Method Details
#and(other) ⇒ Object Also known as: &
47 48 49 |
# File 'lib/declarative_policy/rule.rb', line 47 def and(other) And.make([self, other]) end |
#cached_pass?(_context) ⇒ Boolean
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
27 28 29 |
# File 'lib/declarative_policy/rule.rb', line 27 def cached_pass?(_context) raise 'abstract' end |
#inspect ⇒ Object
59 60 61 |
# File 'lib/declarative_policy/rule.rb', line 59 def inspect "#<Rule #{repr}>" end |
#negate ⇒ Object Also known as: ~
51 52 53 |
# File 'lib/declarative_policy/rule.rb', line 51 def negate Not.make(self) end |
#or(other) ⇒ Object Also known as: |
convenience combination methods
43 44 45 |
# File 'lib/declarative_policy/rule.rb', line 43 def or(other) Or.make([self, other]) end |
#pass?(_context) ⇒ Boolean
true or false whether this rule passes. ‘context` is a policy - an instance of DeclarativePolicy::Base.
20 21 22 |
# File 'lib/declarative_policy/rule.rb', line 20 def pass?(_context) raise 'abstract' end |
#score(_context) ⇒ Object
abstractly, how long would it take to compute this rule? lower-scored rules are tried first.
33 34 35 |
# File 'lib/declarative_policy/rule.rb', line 33 def score(_context) raise 'abstract' end |
#simplify ⇒ Object
unwrap double negatives and nested and/or
38 39 40 |
# File 'lib/declarative_policy/rule.rb', line 38 def simplify self end |