Skip to content

Commit

Permalink
chore: move BKTEvaluationDetails to a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
duyhungtnn committed Sep 5, 2024
1 parent 7a0907e commit 6e761ac
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 61 deletions.
61 changes: 0 additions & 61 deletions Bucketeer/Sources/Public/BKTEvaluation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,64 +21,3 @@ public struct BKTEvaluation: Equatable {
case prerequisite = "PREREQUISITE"
}
}

public struct BKTEvaluationDetails<T:Equatable>: Equatable {
public let featureId: String
public let featureVersion: Int
public let userId: String
public let variationId: String
public let variationName: String
public let variationValue: T
public let reason: Reason

public enum Reason: String, Codable, Hashable {
case target = "TARGET"
case rule = "RULE"
case `default` = "DEFAULT"
case client = "CLIENT"
case offVariation = "OFF_VARIATION"
case prerequisite = "PREREQUISITE"

public static func fromString(value: String) -> Reason {
return Reason(rawValue: value) ?? .client
}
}

public static func == (lhs: BKTEvaluationDetails<T>, rhs: BKTEvaluationDetails<T>) -> Bool {
return lhs.featureId == rhs.featureId &&
lhs.featureVersion == rhs.featureVersion &&
lhs.userId == rhs.userId &&
lhs.variationId == rhs.variationId &&
lhs.variationName == rhs.variationName &&
lhs.reason == rhs.reason &&
lhs.variationValue == rhs.variationValue
}

static func newDefaultInstance(featureId: String, userId: String, defaultValue: T) -> BKTEvaluationDetails<T> {
return BKTEvaluationDetails(
featureId: featureId,
featureVersion: 0,
userId: userId,
variationId: "",
variationName: "",
variationValue: defaultValue,
reason: .client
)
}

public init(featureId: String,
featureVersion: Int,
userId: String,
variationId: String,
variationName: String,
variationValue: T,
reason: Reason) {
self.featureId = featureId
self.featureVersion = featureVersion
self.userId = userId
self.variationId = variationId
self.variationName = variationName
self.variationValue = variationValue
self.reason = reason
}
}
62 changes: 62 additions & 0 deletions Bucketeer/Sources/Public/BKTEvaluationDetails.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import Foundation

public struct BKTEvaluationDetails<T:Equatable>: Equatable {
public let featureId: String
public let featureVersion: Int
public let userId: String
public let variationId: String
public let variationName: String
public let variationValue: T
public let reason: Reason

public enum Reason: String, Codable, Hashable {
case target = "TARGET"
case rule = "RULE"
case `default` = "DEFAULT"
case client = "CLIENT"
case offVariation = "OFF_VARIATION"
case prerequisite = "PREREQUISITE"

public static func fromString(value: String) -> Reason {
return Reason(rawValue: value) ?? .client
}
}

public static func == (lhs: BKTEvaluationDetails<T>, rhs: BKTEvaluationDetails<T>) -> Bool {
return lhs.featureId == rhs.featureId &&
lhs.featureVersion == rhs.featureVersion &&
lhs.userId == rhs.userId &&
lhs.variationId == rhs.variationId &&
lhs.variationName == rhs.variationName &&
lhs.reason == rhs.reason &&
lhs.variationValue == rhs.variationValue
}

static func newDefaultInstance(featureId: String, userId: String, defaultValue: T) -> BKTEvaluationDetails<T> {
return BKTEvaluationDetails(
featureId: featureId,
featureVersion: 0,
userId: userId,
variationId: "",
variationName: "",
variationValue: defaultValue,
reason: .client
)
}

public init(featureId: String,
featureVersion: Int,
userId: String,
variationId: String,
variationName: String,
variationValue: T,
reason: Reason) {
self.featureId = featureId
self.featureVersion = featureVersion
self.userId = userId
self.variationId = variationId
self.variationName = variationName
self.variationValue = variationValue
self.reason = reason
}
}

0 comments on commit 6e761ac

Please sign in to comment.