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.
149 150 151 |
# File 'lib/declarative_policy/rule.rb', line 149 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
162 163 164 165 166 167 |
# File 'lib/declarative_policy/rule.rb', line 162 def cached_pass?(context) runner = context.runner(@ability) return unless runner.cached? runner.pass? end |
#description(context) ⇒ Object
169 170 171 |
# File 'lib/declarative_policy/rule.rb', line 169 def description(context) "User can #{@ability.inspect}" end |
#pass?(context) ⇒ Boolean
158 159 160 |
# File 'lib/declarative_policy/rule.rb', line 158 def pass?(context) context.allowed?(@ability) end |
#repr ⇒ Object
173 174 175 |
# File 'lib/declarative_policy/rule.rb', line 173 def repr "can?(#{@ability.inspect})" end |
#score(context) ⇒ Object
We ask the ability's runner for a score
154 155 156 |
# File 'lib/declarative_policy/rule.rb', line 154 def score(context) context.runner(@ability).score end |