Class: LaunchDarkly::OpenFeature::Impl::EvaluationContextConverter
- Inherits:
-
Object
- Object
- LaunchDarkly::OpenFeature::Impl::EvaluationContextConverter
- Defined in:
- lib/ldclient-openfeature/impl/context_converter.rb
Instance Method Summary collapse
-
#initialize(logger) ⇒ EvaluationContextConverter
constructor
A new instance of EvaluationContextConverter.
-
#to_ld_context(context) ⇒ LaunchDarkly::LDContext
Create an LDContext from an EvaluationContext.
Constructor Details
#initialize(logger) ⇒ EvaluationContextConverter
Returns a new instance of EvaluationContextConverter.
13 14 15 |
# File 'lib/ldclient-openfeature/impl/context_converter.rb', line 13 def initialize(logger) @logger = logger end |
Instance Method Details
#to_ld_context(context) ⇒ LaunchDarkly::LDContext
Create an LDContext from an EvaluationContext.
A context will always be created, but the created context may be invalid. Log messages will be written to indicate the source of the problem.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ldclient-openfeature/impl/context_converter.rb', line 27 def to_ld_context(context) kind = context.field('kind') return build_multi_context(context) if kind == "multi" unless kind.nil? || kind.is_a?(String) @logger.warn("'kind' was set to a non-string value; defaulting to user") kind = 'user' end targeting_key = context.targeting_key key = context.field('key') targeting_key = get_targeting_key(targeting_key, key) kind ||= 'user' build_single_context(context.fields, kind, targeting_key) end |