Class: Datadog::OpenFeature::NativeEvaluator

Inherits:
Object
  • Object
show all
Defined in:
lib/datadog/open_feature/native_evaluator.rb

Overview

This class is an interface of evaluation logic using native extension

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ NativeEvaluator

NOTE: In a currect implementation configuration is expected to be a raw

JSON string containing feature flags (straight from the remote config)
in the format expected by `libdatadog` without any modifications


12
13
14
# File 'lib/datadog/open_feature/native_evaluator.rb', line 12

def initialize(configuration)
  @configuration = Core::FeatureFlags::Configuration.new(configuration)
end

Instance Method Details

#get_assignment(flag_key, default_value:, expected_type:, context:) ⇒ Core::FeatureFlags::ResolutionDetails

Returns the assignment for a given flag key based on the feature flags configuration

Parameters:

  • flag_key (String)

    The key of the feature flag

  • default_value (Object)

    The default value to return if the flag is not found or evaluation itself fails

  • expected_type (Symbol)

    The expected type of the flag

  • context (Hash)

    The context of the evaluation, containing targeting key and other attributes

Returns:



27
28
29
30
31
32
33
34
35
# File 'lib/datadog/open_feature/native_evaluator.rb', line 27

def get_assignment(flag_key, default_value:, expected_type:, context:)
  result = @configuration.get_assignment(flag_key, expected_type, context)

  # NOTE: This is a special case when we need to fallback to the default
  #       value, even tho the evaluation itself doesn't produce an error
  #       resolution details
  result.value = default_value if result.variant.nil?
  result
end