Skip to content

Commit 6b17509

Browse files
committed
Reorder get_assignment method parameters
1 parent b9dbe15 commit 6b17509

File tree

9 files changed

+34
-34
lines changed

9 files changed

+34
-34
lines changed

lib/datadog/open_feature/binding/internal_evaluator.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ def initialize(ufc_json)
3737
# traffic splitting, and allocation matching.
3838
#
3939
# @param flag_key [String] The unique identifier for the feature flag
40+
# @param default_value [Object] Default value to return when flag evaluation fails or no allocation matches
4041
# @param evaluation_context [Hash, nil] Context data for flag evaluation.
4142
# When using OpenFeature SDK, pass evaluation_context&.fields to extract
4243
# the hash representation. Common fields include 'targeting_key' and custom attributes.
4344
# @param expected_type [String] Expected value type: "string", "integer", "float", "boolean", or "object"
44-
# @param default_value [Object] Default value to return when flag evaluation fails or no allocation matches
4545
# @return [ResolutionDetails] Evaluation result where result.value is ensured to never be nil.
4646
# For successful evaluations, contains the flag's assigned value and metadata.
4747
# For errors or disabled flags, contains the provided default_value.
48-
def get_assignment(flag_key, evaluation_context, expected_type, default_value)
48+
def get_assignment(flag_key, default_value, evaluation_context, expected_type)
4949
# Return error result if JSON parsing failed during initialization
5050
if @parse_error
5151
return create_evaluation_error(

lib/datadog/open_feature/evaluation_engine.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def fetch_value(flag_key:, expected_type:, evaluation_context: nil, default_valu
4545

4646
string_expected_type = TYPE_MAP[expected_type] || expected_type
4747

48-
result = @evaluator.get_assignment(flag_key, evaluation_context&.fields, string_expected_type, default_value)
48+
result = @evaluator.get_assignment(flag_key, default_value, evaluation_context&.fields, string_expected_type)
4949
@reporter.report(result, flag_key: flag_key, context: evaluation_context)
5050

5151
result

lib/datadog/open_feature/noop_evaluator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(_configuration)
1111
# no-op
1212
end
1313

14-
def get_assignment(_flag_key, _evaluation_context, _expected_type, default_value)
14+
def get_assignment(_flag_key, default_value, _evaluation_context, _expected_type)
1515
Binding::ResolutionDetails.new(
1616
value: default_value,
1717
error_code: Ext::PROVIDER_NOT_READY,

sig/datadog/open_feature/binding/internal_evaluator.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module Datadog
1414

1515
def get_assignment: (
1616
::String flag_key,
17+
untyped default_value,
1718
untyped _evaluation_context,
18-
::String? expected_type,
19-
untyped default_value
19+
::String? expected_type
2020
) -> ResolutionDetails
2121

2222
private

sig/datadog/open_feature/noop_evaluator.rbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ module Datadog
55

66
def get_assignment: (
77
::String,
8+
untyped,
89
::OpenFeature::SDK::EvaluationContext?,
9-
::String,
10-
untyped
10+
::String
1111
) -> Binding::ResolutionDetails
1212
end
1313
end

spec/datadog/open_feature/binding/allocation_matching_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
let(:evaluator) { Datadog::OpenFeature::Binding::InternalEvaluator.new(flag_config.to_json) }
4343

4444
it 'skips expired allocations and uses active ones' do
45-
result = evaluator.get_assignment("time_test_flag", {}, 'string', 'test_default')
45+
result = evaluator.get_assignment("time_test_flag", 'test_default', {}, 'string')
4646

4747
expect(result.error_code).to be_nil # nil for successful evaluation
4848
expect(result.value).to eq("treatment_value") # Should use active allocation
@@ -52,7 +52,7 @@
5252
end
5353

5454
it 'returns assignment reason based on allocation properties' do
55-
result = evaluator.get_assignment("time_test_flag", {}, 'string', 'test_default')
55+
result = evaluator.get_assignment("time_test_flag", 'test_default', {}, 'string')
5656

5757
expect(result.reason).to eq("STATIC") # Single split with no shards = static
5858
end
@@ -62,7 +62,7 @@
6262
let(:evaluator) { Datadog::OpenFeature::Binding::InternalEvaluator.new('{"flags": {}}') }
6363

6464
it 'returns error result on flag lookup errors' do
65-
result = evaluator.get_assignment("missing_flag", {}, 'string', 'test_default')
65+
result = evaluator.get_assignment("missing_flag", 'test_default', {}, 'string')
6666

6767
expect(result.error_code).to eq('FLAG_UNRECOGNIZED_OR_DISABLED')
6868
expect(result.value).to eq('test_default') # Internal evaluator returns default_value for errors
@@ -71,9 +71,9 @@
7171
end
7272

7373
it 'returns consistent error results for different types' do
74-
string_result = evaluator.get_assignment("missing", {}, 'string', 'test_default')
75-
number_result = evaluator.get_assignment("missing", {}, 'float', 'test_default')
76-
bool_result = evaluator.get_assignment("missing", {}, 'boolean', 'test_default')
74+
string_result = evaluator.get_assignment("missing", 'test_default', {}, 'string')
75+
number_result = evaluator.get_assignment("missing", 'test_default', {}, 'float')
76+
bool_result = evaluator.get_assignment("missing", 'test_default', {}, 'boolean')
7777

7878
expect(string_result.value).to eq('test_default') # Internal evaluator returns default_value
7979
expect(number_result.value).to eq('test_default')
@@ -107,7 +107,7 @@
107107
}
108108

109109
evaluator = Datadog::OpenFeature::Binding::InternalEvaluator.new(config_with_time_bounds.to_json)
110-
result = evaluator.get_assignment("timed_flag", {}, 'boolean', 'test_default')
110+
result = evaluator.get_assignment("timed_flag", 'test_default', {}, 'boolean')
111111

112112
expect(result.error_code).to be_nil # nil for successful evaluation
113113
expect(result.reason).to eq("TARGETING_MATCH") # Has time bounds

spec/datadog/open_feature/binding/internal_evaluator_spec.rb

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
context 'with invalid UFC JSON' do
2929
it 'stores parse error for malformed JSON' do
3030
evaluator = described_class.new('invalid json')
31-
result = evaluator.get_assignment('any_flag', {}, 'string', 'test_default')
31+
result = evaluator.get_assignment('any_flag', 'test_default', {}, 'string')
3232

3333
expect(result.error_code).to eq('CONFIGURATION_PARSE_ERROR')
3434
expect(result.error_message).to eq('failed to parse configuration')
@@ -38,7 +38,7 @@
3838

3939
it 'stores configuration missing error for empty JSON' do
4040
evaluator = described_class.new('')
41-
result = evaluator.get_assignment('any_flag', {}, 'string', 'test_default')
41+
result = evaluator.get_assignment('any_flag', 'test_default', {}, 'string')
4242

4343
expect(result.error_code).to eq('CONFIGURATION_MISSING')
4444
expect(result.error_message).to eq('flags configuration is missing')
@@ -55,7 +55,7 @@
5555
let(:bad_evaluator) { described_class.new('invalid json') }
5656

5757
it 'returns the initialization error' do
58-
result = bad_evaluator.get_assignment('any_flag', {}, 'string', 'test_default')
58+
result = bad_evaluator.get_assignment('any_flag', 'test_default', {}, 'string')
5959

6060
expect(result.error_code).to eq('CONFIGURATION_PARSE_ERROR')
6161
expect(result.error_message).to eq('failed to parse configuration')
@@ -67,7 +67,7 @@
6767

6868
context 'with type validation' do
6969
it 'returns TYPE_MISMATCH when types do not match' do
70-
result = evaluator.get_assignment('numeric_flag', {}, 'boolean', 'test_default')
70+
result = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'boolean')
7171

7272
expect(result.error_code).to eq('TYPE_MISMATCH')
7373
expect(result.error_message).to eq('invalid flag type (expected: boolean, found: NUMERIC)')
@@ -77,7 +77,7 @@
7777
end
7878

7979
it 'succeeds when types match' do
80-
result = evaluator.get_assignment('numeric_flag', {}, 'float', 'test_default')
80+
result = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'float')
8181

8282
expect(result.error_code).to be_nil # nil for successful allocation match
8383
expect(result.error_message).to be_nil # nil for successful cases
@@ -89,7 +89,7 @@
8989
end
9090

9191
it 'succeeds when expected_type is nil (no validation)' do
92-
result = evaluator.get_assignment('numeric_flag', {}, nil, 'test_default')
92+
result = evaluator.get_assignment('numeric_flag', 'test_default', {}, nil)
9393

9494
expect(result.error_code).to be_nil # nil for successful allocation match
9595
expect(result.error_message).to be_nil # nil for successful cases
@@ -123,7 +123,7 @@
123123
it 'accepts hash evaluation contexts including from OpenFeature SDK fields' do
124124
# Test with hash-based evaluation context
125125
hash_context = {'targeting_key' => 'user123', 'attr1' => 'value1'}
126-
hash_result = evaluator.get_assignment('numeric_flag', hash_context, 'float', 'test_default')
126+
hash_result = evaluator.get_assignment('numeric_flag', 'test_default', hash_context, 'float')
127127

128128
expect(hash_result.error_code).to be_nil
129129
expect(hash_result.value).not_to be_nil
@@ -135,7 +135,7 @@
135135
fields: {'attr1' => 'value1'}
136136
)
137137

138-
sdk_result = evaluator.get_assignment('numeric_flag', sdk_context.fields, 'float', 'test_default')
138+
sdk_result = evaluator.get_assignment('numeric_flag', 'test_default', sdk_context.fields, 'float')
139139

140140
expect(sdk_result.error_code).to be_nil
141141
expect(sdk_result.value).not_to be_nil
@@ -174,35 +174,35 @@
174174

175175
it 'uses consistent error codes matching Rust implementation' do
176176
# Test all error types
177-
flag_not_found = evaluator.get_assignment('missing', {}, 'string', 'test_default')
177+
flag_not_found = evaluator.get_assignment('missing', 'test_default', {}, 'string')
178178
expect(flag_not_found.error_code).to eq('FLAG_UNRECOGNIZED_OR_DISABLED')
179179
expect(flag_not_found.value).to eq('test_default')
180180
expect(flag_not_found.variant).to be_nil
181181
expect(flag_not_found.flag_metadata).to eq({})
182182

183-
flag_disabled = evaluator.get_assignment('disabled_flag', {}, 'integer', 'test_default')
183+
flag_disabled = evaluator.get_assignment('disabled_flag', 'test_default', {}, 'integer')
184184
expect(flag_disabled.error_code).to be_nil # Disabled flags are successful cases with nil error_code
185185
expect(flag_disabled.error_message).to be_nil # nil for successful disabled cases
186186
expect(flag_disabled.reason).to eq('DISABLED') # Disabled reason
187187
expect(flag_disabled.value).to eq('test_default')
188188
expect(flag_disabled.variant).to be_nil
189189
expect(flag_disabled.flag_metadata).to eq({})
190190

191-
type_mismatch = evaluator.get_assignment('numeric_flag', {}, 'boolean', 'test_default')
191+
type_mismatch = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'boolean')
192192
expect(type_mismatch.error_code).to eq('TYPE_MISMATCH')
193193
expect(type_mismatch.value).to eq('test_default')
194194
expect(type_mismatch.variant).to be_nil
195195
expect(type_mismatch.flag_metadata).to eq({})
196196
end
197197

198198
it 'provides descriptive error messages matching Rust format' do
199-
result = evaluator.get_assignment('missing_flag', {}, 'string', 'test_default')
199+
result = evaluator.get_assignment('missing_flag', 'test_default', {}, 'string')
200200
expect(result.error_message).to eq('flag is missing in configuration, it is either unrecognized or disabled')
201201
expect(result.value).to eq('test_default')
202202
expect(result.variant).to be_nil
203203
expect(result.flag_metadata).to eq({})
204204

205-
type_result = evaluator.get_assignment('numeric_flag', {}, 'boolean', 'test_default')
205+
type_result = evaluator.get_assignment('numeric_flag', 'test_default', {}, 'boolean')
206206
expect(type_result.error_message).to match(/invalid flag type \(expected: .*, found: .*\)/)
207207
expect(type_result.value).to eq('test_default')
208208
expect(type_result.variant).to be_nil
@@ -241,7 +241,7 @@
241241
evaluation_context['targeting_key'] = targeting_key if targeting_key # Convert camelCase to snake_case
242242

243243
# Execute test case
244-
result = evaluator.get_assignment(flag_key, evaluation_context, expected_type, 'test_default')
244+
result = evaluator.get_assignment(flag_key, 'test_default', evaluation_context, expected_type)
245245

246246
# Wrap expectations in aggregate_failures for better error reporting
247247
aggregate_failures "Test case ##{index + 1}: #{targeting_key} with #{attributes.keys.join(", ")}" do

spec/datadog/open_feature/binding/rule_evaluation_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666

6767
it 'matches allocation when first rule passes' do
6868
admin_context = {"user_type" => "admin", "age" => 30}
69-
result = evaluator.get_assignment("multi_rule_flag", admin_context, 'string', 'test_default')
69+
result = evaluator.get_assignment("multi_rule_flag", 'test_default', admin_context, 'string')
7070

7171
expect(result.error_code).to be_nil
7272
expect(result.value).to eq("special_value")
@@ -75,7 +75,7 @@
7575

7676
it 'matches allocation when second rule passes' do
7777
senior_context = {"user_type" => "regular", "age" => 70}
78-
result = evaluator.get_assignment("multi_rule_flag", senior_context, 'string', 'test_default')
78+
result = evaluator.get_assignment("multi_rule_flag", 'test_default', senior_context, 'string')
7979

8080
expect(result.error_code).to be_nil
8181
expect(result.value).to eq("special_value")
@@ -84,7 +84,7 @@
8484

8585
it 'matches allocation when both rules pass' do
8686
admin_senior_context = {"user_type" => "admin", "age" => 70}
87-
result = evaluator.get_assignment("multi_rule_flag", admin_senior_context, 'string', 'test_default')
87+
result = evaluator.get_assignment("multi_rule_flag", 'test_default', admin_senior_context, 'string')
8888

8989
expect(result.error_code).to be_nil
9090
expect(result.value).to eq("special_value")
@@ -93,7 +93,7 @@
9393

9494
it 'uses fallback allocation when no rules pass' do
9595
regular_context = {"user_type" => "regular", "age" => 30}
96-
result = evaluator.get_assignment("multi_rule_flag", regular_context, 'string', 'test_default')
96+
result = evaluator.get_assignment("multi_rule_flag", 'test_default', regular_context, 'string')
9797

9898
expect(result.error_code).to be_nil
9999
expect(result.value).to eq("default_value")

spec/datadog/open_feature/noop_evaluator_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
subject(:evaluator) { described_class.new(nil) }
88

99
describe '#get_assignment' do
10-
let(:result) { evaluator.get_assignment('flag', nil, :string, 'default_value') }
10+
let(:result) { evaluator.get_assignment('flag', 'default_value', nil, :string) }
1111

1212
it 'returns provider not ready result' do
1313
expect(result.do_log).to be(false)

0 commit comments

Comments
 (0)