Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Handle redundant warnings, run SwiftLint #46

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 25 additions & 30 deletions Sources/FeaturevisorSDK/Instance+Activation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,36 @@ extension FeaturevisorInstance {
// MARK: - Activate

public func activate(featureKey: FeatureKey, context: Context = [:]) -> VariationValue? {
do {
let evaluation = evaluateVariation(featureKey: featureKey, context: context)
let variationValue = evaluation.variation?.value ?? evaluation.variationValue

guard let variationValue else {
return nil
}

let finalContext = interceptContext != nil ? interceptContext!(context) : context
let evaluation = evaluateVariation(featureKey: featureKey, context: context)
let variationValue = evaluation.variation?.value ?? evaluation.variationValue

var captureContext: Context = [:]
guard let variationValue else {
return nil
}

let attributesForCapturing = datafileReader.getAllAttributes()
.filter { $0.capture == true }
let finalContext = interceptContext != nil ? interceptContext!(context) : context

attributesForCapturing.forEach({ attribute in
if finalContext[attribute.key] != nil {
captureContext[attribute.key] = context[attribute.key]
}
})
var captureContext: Context = [:]

emitter.emit(
EventName.activation,
featureKey,
variationValue,
finalContext,
captureContext,
evaluation
)
let attributesForCapturing = datafileReader.getAllAttributes()
.filter { $0.capture == true }

return variationValue
}
catch {
logger.error("activate", ["featureKey": featureKey, "error": error])
return nil
}
attributesForCapturing.forEach({ attribute in
if finalContext[attribute.key] != nil {
captureContext[attribute.key] = context[attribute.key]
}
})

emitter.emit(
EventName.activation,
featureKey,
variationValue,
finalContext,
captureContext,
evaluation
)

return variationValue
}
}
7 changes: 4 additions & 3 deletions Sources/FeaturevisorSDK/Instance+Refresh.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ extension FeaturevisorInstance {

statuses.refreshInProgress = true

try? fetchDatafileContent(from: datafileUrl, handleDatafileFetch: handleDatafileFetch) {
[weak self] result in
try? fetchDatafileContent(
from: datafileUrl,
handleDatafileFetch: handleDatafileFetch) { [weak self] result in
guard let self else {
return
}
Expand Down Expand Up @@ -51,7 +52,7 @@ extension FeaturevisorInstance {

public func startRefreshing() {

guard let datafileUrl else {
guard datafileUrl != nil else {
logger.error("cannot start refreshing since `datafileUrl` is not provided")
return
}
Expand Down
5 changes: 3 additions & 2 deletions Sources/FeaturevisorSDK/Instance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ public class FeaturevisorInstance {
if let datafileUrl = options.datafileUrl {
datafileReader = DatafileReader(datafileContent: options.datafile ?? emptyDatafile)

try fetchDatafileContent(from: datafileUrl, handleDatafileFetch: handleDatafileFetch) {
[weak self] result in
try fetchDatafileContent(
from: datafileUrl,
handleDatafileFetch: handleDatafileFetch) { [weak self] result in
switch result {
case .success(let datafileContent):
self?.datafileReader = DatafileReader(datafileContent: datafileContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ extension KeyedDecodingContainer {
return try JSONDecoder().decode(T.self, from: data)
}

func decodeStringifiedIfPresent<T>(_ type: T.Type, forKey key: KeyedDecodingContainer<K>.Key)
throws -> T? where T: Decodable
{
func decodeStringifiedIfPresent<T>(
_ type: T.Type,
forKey key: KeyedDecodingContainer<K>.Key) throws -> T? where T: Decodable {

guard self.contains(key) else {
return nil
Expand Down
1 change: 1 addition & 0 deletions Tests/FeaturevisorSDKTests/InstanceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ class FeaturevisorInstanceTests: XCTestCase {
}

// THEN
XCTAssertEqual(sdk.getRevision(), "4")
XCTAssertEqual(refreshedCount, expectedRefreshCount)
}

Expand Down