Class: DeclarativePolicy::Rule::Ability

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

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

#abilityObject (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

Returns:

  • (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

Returns:

  • (Boolean)

158
159
160
# File 'lib/declarative_policy/rule.rb', line 158

def pass?(context)
  context.allowed?(@ability)
end

#reprObject


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