Class: LaunchDarkly::Impl::Evaluator Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Evaluator
- Defined in:
- lib/ldclient-rb/impl/evaluator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Encapsulates the feature flag evaluation logic. The Evaluator has no knowledge of the rest of the SDK environment; if it needs to retrieve flags or segments that are referenced by a flag, it does so through a simple function that is provided in the constructor. It also produces feature requests as appropriate for any referenced prerequisite flags, but does not send them.
Defined Under Namespace
Classes: EvalResult
Class Method Summary collapse
-
.error_result(errorKind, value = nil) ⇒ Object
private
Helper function used internally to construct an EvaluationDetail for an error result.
- .make_big_segment_ref(segment) ⇒ Object private
Instance Method Summary collapse
-
#evaluate(flag, context) ⇒ Array<EvalResult, EvaluatorState>
private
The client's entry point for evaluating a flag.
-
#initialize(get_flag, get_segment, get_big_segments_membership, logger) ⇒ Evaluator
constructor
private
A single Evaluator is instantiated for each client instance.
Constructor Details
#initialize(get_flag, get_segment, get_big_segments_membership, logger) ⇒ Evaluator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
A single Evaluator is instantiated for each client instance.
113 114 115 116 117 118 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 113 def initialize(get_flag, get_segment, get_big_segments_membership, logger) @get_flag = get_flag @get_segment = get_segment @get_big_segments_membership = get_big_segments_membership @logger = logger end |
Class Method Details
.error_result(errorKind, value = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Helper function used internally to construct an EvaluationDetail for an error result.
137 138 139 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 137 def self.error_result(errorKind, value = nil) EvaluationDetail.new(value, nil, EvaluationReason.error(errorKind)) end |
.make_big_segment_ref(segment) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
176 177 178 179 180 181 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 176 def self.make_big_segment_ref(segment) # method is visible for testing # The format of Big Segment references is independent of what store implementation is being # used; the store implementation receives only this string and does not know the details of # the data model. The Relay Proxy will use the same format when writing to the store. "#{segment.key}.g#{segment.generation}" end |
Instance Method Details
#evaluate(flag, context) ⇒ Array<EvalResult, EvaluatorState>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The client's entry point for evaluating a flag. The returned EvalResult contains the evaluation result and
any events that were generated for prerequisite flags; its value will be nil if the flag returns the
default value. Error conditions produce a result with a nil value and an error reason, not an exception.
inspecting the evaluation process
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/ldclient-rb/impl/evaluator.rb', line 149 def evaluate(flag, context) state = EvaluatorState.new(flag) result = EvalResult.new begin detail = eval_internal(flag, context, result, state) rescue EvaluationException => exn Impl::Util.log_exception(@logger, "Unexpected error when evaluating flag #{flag.key}", exn) result.detail = EvaluationDetail.new(nil, nil, EvaluationReason::error(exn.error_kind)) return result, state rescue => exn Impl::Util.log_exception(@logger, "Unexpected error when evaluating flag #{flag.key}", exn) result.detail = EvaluationDetail.new(nil, nil, EvaluationReason::error(EvaluationReason::ERROR_EXCEPTION)) return result, state end unless result.big_segments_status.nil? # If big_segments_status is non-nil at the end of the evaluation, it means a query was done at # some point and we will want to include the status in the evaluation reason. detail = EvaluationDetail.new(detail.value, detail.variation_index, detail.reason.with_big_segments_status(result.big_segments_status)) end result.detail = detail [result, state] end |