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

Constant Summary collapse

INVALID_FLAG_CONFIGURATION_ERROR_MESSAGE =
"flag configuration is invalid or unsupported"

Instance Attribute Summary collapse

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



17
18
19
20
# File 'lib/datadog/open_feature/native_evaluator.rb', line 17

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

Instance Attribute Details

#observe_full_evaluation_data ⇒ Object (readonly)

Returns the value of attribute observe_full_evaluation_data.



22
23
24
# File 'lib/datadog/open_feature/native_evaluator.rb', line 22

def observe_full_evaluation_data
  @observe_full_evaluation_data
end

Instance Method Details

#get_assignment(flag_key, default_value:, expected_type:, context:) ⇒ 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:



35
36
37
38
39
40
41
# File 'lib/datadog/open_feature/native_evaluator.rb', line 35

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

  return invalid_flag_configuration_error(default_value) if invalid_flag_configuration?(result)

  build_resolution_details(result, default_value)
end