Class: DeclarativePolicy::Rule::Condition
- Defined in:
- lib/declarative_policy/rule.rb
Overview
A rule that checks a condition. This is the type of rule that results from a basic bareword in the rule dsl (see RuleDsl#method_missing).
Instance Method Summary collapse
-
#cached_pass?(context) ⇒ Boolean
returns nil unless it’s already cached.
- #description(context) ⇒ Object
-
#initialize(name) ⇒ Condition
constructor
A new instance of Condition.
-
#pass?(context) ⇒ Boolean
Let the ManifestCondition from the context decide whether we pass.
- #repr ⇒ Object
-
#score(context) ⇒ Object
we delegate scoring to the condition.
Methods inherited from Base
#and, #inspect, make, #negate, #or, #simplify
Constructor Details
#initialize(name) ⇒ Condition
Returns a new instance of Condition.
68 69 70 |
# File 'lib/declarative_policy/rule.rb', line 68 def initialize(name) @name = name end |
Instance Method Details
#cached_pass?(context) ⇒ Boolean
returns nil unless it’s already cached
85 86 87 88 89 90 |
# File 'lib/declarative_policy/rule.rb', line 85 def cached_pass?(context) condition = context.condition(@name) return unless condition.cached? condition.pass? end |
#description(context) ⇒ Object
92 93 94 |
# File 'lib/declarative_policy/rule.rb', line 92 def description(context) context.class.conditions[@name].description end |
#pass?(context) ⇒ Boolean
Let the ManifestCondition from the context decide whether we pass.
80 81 82 |
# File 'lib/declarative_policy/rule.rb', line 80 def pass?(context) context.condition(@name).pass? end |
#repr ⇒ Object
96 97 98 |
# File 'lib/declarative_policy/rule.rb', line 96 def repr @name.to_s end |
#score(context) ⇒ Object
we delegate scoring to the condition. See ManifestCondition#score.
74 75 76 |
# File 'lib/declarative_policy/rule.rb', line 74 def score(context) context.condition(@name).score end |