Class: DeclarativePolicy::Rule::Ability
- Defined in:
- lib/declarative_policy/rule.rb
Overview
A rule constructed from RuleDsl#can?. Computes a different ability on the same subject.
Instance Attribute Summary collapse
-
#ability ⇒ Object
readonly
Returns the value of attribute ability.
Instance Method Summary collapse
- #cached_pass?(context) ⇒ Boolean
- #description(_context) ⇒ Object
-
#initialize(ability) ⇒ Ability
constructor
A new instance of Ability.
- #pass?(context) ⇒ Boolean
- #repr ⇒ Object
-
#score(context) ⇒ Object
We ask the ability’s runner for a score.
Methods inherited from Base
#and, #inspect, make, #negate, #or, #simplify
Constructor Details
#initialize(ability) ⇒ Ability
Returns a new instance of Ability.
150 151 152 |
# File 'lib/declarative_policy/rule.rb', line 150 def initialize(ability) @ability = ability end |
Instance Attribute Details
#ability ⇒ Object (readonly)
Returns the value of attribute ability.
148 149 150 |
# File 'lib/declarative_policy/rule.rb', line 148 def ability @ability end |
Instance Method Details
#cached_pass?(context) ⇒ Boolean
163 164 165 166 167 168 |
# File 'lib/declarative_policy/rule.rb', line 163 def cached_pass?(context) runner = context.runner(@ability) return unless runner.cached? runner.pass? end |
#description(_context) ⇒ Object
170 171 172 |
# File 'lib/declarative_policy/rule.rb', line 170 def description(_context) "User can #{@ability.inspect}" end |
#pass?(context) ⇒ Boolean
159 160 161 |
# File 'lib/declarative_policy/rule.rb', line 159 def pass?(context) context.allowed?(@ability) end |
#repr ⇒ Object
174 175 176 |
# File 'lib/declarative_policy/rule.rb', line 174 def repr "can?(#{@ability.inspect})" end |
#score(context) ⇒ Object
We ask the ability’s runner for a score
155 156 157 |
# File 'lib/declarative_policy/rule.rb', line 155 def score(context) context.runner(@ability).score end |