Class: DeclarativePolicy::Rule::DelegatedCondition
- Inherits:
-
Base
- Object
- Base
- DeclarativePolicy::Rule::DelegatedCondition
show all
- Defined in:
- lib/declarative_policy/rule.rb
Overview
A rule constructed from DelegateDsl - using a condition from a delegated policy.
Constant Summary
collapse
- MissingDelegate =
Internal use only - this is rescued each time it’s raised.
Class.new(StandardError)
Instance Method Summary
collapse
Methods inherited from Base
#and, #inspect, make, #negate, #or, #simplify
Constructor Details
Returns a new instance of DelegatedCondition.
107
108
109
110
|
# File 'lib/declarative_policy/rule.rb', line 107
def initialize(delegate_name, name)
@delegate_name = delegate_name
@name = name
end
|
Instance Method Details
#cached_pass?(context) ⇒ Boolean
125
126
127
128
129
130
131
132
|
# File 'lib/declarative_policy/rule.rb', line 125
def cached_pass?(context)
condition = delegated_context(context).condition(@name)
return unless condition.cached?
condition.pass?
rescue MissingDelegate
false
end
|
#delegated_context(context) ⇒ Object
112
113
114
115
116
117
|
# File 'lib/declarative_policy/rule.rb', line 112
def delegated_context(context)
policy = context.delegated_policies[@delegate_name]
raise MissingDelegate if policy.nil?
policy
end
|
#pass?(context) ⇒ Boolean
134
135
136
137
138
|
# File 'lib/declarative_policy/rule.rb', line 134
def pass?(context)
delegated_context(context).condition(@name).pass?
rescue MissingDelegate
false
end
|
#repr ⇒ Object
140
141
142
|
# File 'lib/declarative_policy/rule.rb', line 140
def repr
"#{@delegate_name}.#{@name}"
end
|
#score(context) ⇒ Object
119
120
121
122
123
|
# File 'lib/declarative_policy/rule.rb', line 119
def score(context)
delegated_context(context).condition(@name).score
rescue MissingDelegate
0
end
|