Skip to content

Commit 81c9fa2

Browse files
refactor!: Add eval details to finally hook
Signed-off-by: Fabrizio Demaria <[email protected]>
1 parent b90d593 commit 81c9fa2

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

Sources/OpenFeature/Hook.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public protocol Hook {
1111

1212
func error<HookValue>(ctx: HookContext<HookValue>, error: Error, hints: [String: Any])
1313

14-
func finally<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any])
14+
func finally<HookValue>(ctx: HookContext<HookValue>, details: FlagEvaluationDetails<HookValue>, hints: [String: Any])
1515

1616
func supportsFlagValueType(flagValueType: FlagValueType) -> Bool
1717
}
@@ -31,7 +31,7 @@ extension Hook {
3131
// Default implementation
3232
}
3333

34-
public func finally<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any]) {
34+
public func finally<HookValue>(ctx: HookContext<HookValue>, details: FlagEvaluationDetails<HookValue>, hints: [String: Any]) {
3535
// Default implementation
3636
}
3737

Sources/OpenFeature/HookSupport.swift

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,14 @@ class HookSupport {
3333
}
3434

3535
func finallyHooks<T>(
36-
flagValueType: FlagValueType, hookCtx: HookContext<T>, hooks: [any Hook], hints: [String: Any]
36+
flagValueType: FlagValueType,
37+
hookCtx: HookContext<T>,
38+
details: FlagEvaluationDetails<T>,
39+
hooks: [any Hook],
40+
hints: [String: Any]
3741
) {
3842
hooks
3943
.filter { $0.supportsFlagValueType(flagValueType: flagValueType) }
40-
.forEach { $0.finally(ctx: hookCtx, hints: hints) }
44+
.forEach { $0.finally(ctx: hookCtx, details: details, hints: hints) }
4145
}
4246
}

Sources/OpenFeature/OpenFeatureClient.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ extension OpenFeatureClient {
144144
flagValueType: T.flagValueType, hookCtx: hookCtx, error: error, hooks: mergedHooks, hints: hints)
145145
}
146146
hookSupport.finallyHooks(
147-
flagValueType: T.flagValueType, hookCtx: hookCtx, hooks: mergedHooks, hints: hints)
147+
flagValueType: T.flagValueType, hookCtx: hookCtx, details: details, hooks: mergedHooks, hints: hints)
148148
return details
149149
}
150150

Tests/OpenFeatureTests/Helpers/BooleanHookMock.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class BooleanHookMock: Hook {
3838
self.addEval(self.prefix.isEmpty ? "error" : "\(self.prefix) error")
3939
}
4040

41-
func finally<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any]) {
41+
func finally<HookValue>(ctx: HookContext<HookValue>, details: FlagEvaluationDetails<HookValue>, hints: [String: Any]) {
4242
finallyCalled += 1
4343
self.addEval(self.prefix.isEmpty ? "finally" : "\(self.prefix) finally")
4444
}

Tests/OpenFeatureTests/Helpers/IntHookMock.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class IntHookMock: Hook {
3838
self.addEval(self.prefix.isEmpty ? "error" : "\(self.prefix) error")
3939
}
4040

41-
func finally<HookValue>(ctx: HookContext<HookValue>, hints: [String: Any]) {
41+
func finally<HookValue>(ctx: HookContext<HookValue>, details: FlagEvaluationDetails<HookValue>, hints: [String: Any]) {
4242
finallyCalled += 1
4343
self.addEval(self.prefix.isEmpty ? "finally" : "\(self.prefix) finally")
4444
}

Tests/OpenFeatureTests/HookSupportTests.swift

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ final class HookSupportTests: XCTestCase {
3737
hookSupport.finallyHooks(
3838
flagValueType: .boolean,
3939
hookCtx: hookContext,
40+
details: FlagEvaluationDetails(flagKey: "", value: false),
4041
hooks: [hook],
4142
hints: [:])
4243

0 commit comments

Comments
 (0)