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

make(*args) click to toggle source
# File lib/declarative_policy/rule.rb, line 13
def self.make(*args)
  new(*args).simplify
end

Public Instance Methods

&(other)
Alias for: and
and(other) click to toggle source
# File lib/declarative_policy/rule.rb, line 47
def and(other)
  And.make([self, other])
end
Also aliased as: &
cached_pass?(_context) click to toggle source

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
inspect() click to toggle source
# File lib/declarative_policy/rule.rb, line 59
def inspect
  "#<Rule #{repr}>"
end
negate() click to toggle source
# File lib/declarative_policy/rule.rb, line 51
def negate
  Not.make(self)
end
Also aliased as: ~
or(other) click to toggle source

convenience combination methods

# File lib/declarative_policy/rule.rb, line 43
def or(other)
  Or.make([self, other])
end
Also aliased as: |
pass?(_context) click to toggle source

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
score(_context) click to toggle source

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
simplify() click to toggle source

unwrap double negatives and nested and/or

# File lib/declarative_policy/rule.rb, line 38
def simplify
  self
end
|(other)
Alias for: or
~()
Alias for: negate