Skip to content

Commit 689c8dc

Browse files
committed
temp
1 parent fe2f808 commit 689c8dc

8 files changed

+199
-156
lines changed
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
//
22
// RemoteConfig+Extensions.swift
3-
//
43
//
5-
// Created by Fumito Ito on 2024/01/25.
4+
//
5+
// Created by Fumito Ito on 2024/02/01.
66
//
77

88
import FirebaseRemoteConfig
99

10-
extension RemoteConfig {
11-
func has(key: String) -> Bool {
12-
allKeys(from: .remote).contains(key) || allKeys(from: .default).contains(key)
10+
extension RemoteConfig: RemoteConfigCompatible {
11+
public func configValue(for key: String) -> RemoteConfigValueCompatible {
12+
configValue(forKey: key)
1313
}
1414
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//
2+
// RemoteConfigCompatible+Extensions.swift
3+
//
4+
//
5+
// Created by Fumito Ito on 2024/01/25.
6+
//
7+
8+
import FirebaseRemoteConfig
9+
10+
extension RemoteConfigCompatible {
11+
func has(key: String) -> Bool {
12+
allKeys(from: .remote).contains(key) || allKeys(from: .default).contains(key)
13+
}
14+
}

Sources/FirebaseRemoteConfigOpenFeatureProvider/Extensions/RemoteConfigValue+Extensions.swift

Lines changed: 2 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -2,110 +2,10 @@
22
// RemoteConfigValue+Extensions.swift
33
//
44
//
5-
// Created by Fumito Ito on 2024/01/25.
5+
// Created by Fumito Ito on 2024/02/01.
66
//
77

88
import Foundation
99
import FirebaseRemoteConfig
10-
import OpenFeature
1110

12-
extension RemoteConfigValue {
13-
var toBooleanEvaluation: ProviderEvaluation<Bool> {
14-
.init(value: boolValue, variant: "\(boolValue)", reason: source.reason.rawValue)
15-
}
16-
17-
var toStringEvaluation: ProviderEvaluation<String> {
18-
guard let value = stringValue else {
19-
return .init(value: "", variant: "", reason: Reason.staticReason.rawValue)
20-
}
21-
22-
return .init(value: value, variant: stringValue, reason: source.reason.rawValue)
23-
}
24-
25-
var toInt64Evaluation: ProviderEvaluation<Int64> {
26-
.init(value: numberValue.int64Value, variant: "\(numberValue.int64Value)", reason: source.reason.rawValue)
27-
}
28-
29-
var toDoubleEvaluation: ProviderEvaluation<Double> {
30-
.init(value: numberValue.doubleValue, variant: "\(numberValue.doubleValue)", reason: source.reason.rawValue)
31-
}
32-
33-
var toDateEvaluation: ProviderEvaluation<Date> {
34-
get throws {
35-
guard let dateString = stringValue else {
36-
throw OpenFeatureError.parseError(message: "指定されたキーから文字列を取得することができない")
37-
}
38-
39-
guard let date = FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.date(from: dateString) else {
40-
throw OpenFeatureError.parseError(message: "指定されたキーから取得した文字列を日付に変換することができない")
41-
}
42-
43-
return .init(value: date, variant: FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.string(from: date), reason: source.reason.rawValue)
44-
}
45-
}
46-
47-
var toValueArrayEvaluation: ProviderEvaluation<[Value]> {
48-
get throws {
49-
guard let jsonValue else {
50-
throw OpenFeatureError.parseError(message: "指定されたキーからJSONオブジェクトを取得することができない")
51-
}
52-
53-
guard let array = jsonValue as? [Any] else {
54-
throw OpenFeatureError.parseError(message: "指定されたキーから配列を取得することができない")
55-
}
56-
57-
let valuedArray = try array.wrapInValue()
58-
59-
return .init(value: valuedArray, variant: valuedArray.description, reason: source.reason.rawValue)
60-
}
61-
}
62-
63-
var toValueStructureEvaluation: ProviderEvaluation<[String: Value]> {
64-
get throws {
65-
guard let jsonValue else {
66-
throw OpenFeatureError.parseError(message: "指定されたキーからJSONオブジェクトを取得することができない")
67-
}
68-
69-
guard let dictionary = jsonValue as? [String: Any] else {
70-
throw OpenFeatureError.parseError(message: "指定されたキーからディクショナリを取得することができない")
71-
}
72-
73-
let valuedDictionary = try dictionary.wrapInValue()
74-
75-
return .init(value: valuedDictionary, variant: valuedDictionary.description, reason: source.reason.rawValue)
76-
}
77-
}
78-
79-
var toObjectEvaluation: ProviderEvaluation<Value> {
80-
get throws {
81-
let value: Value
82-
83-
switch (jsonValue as? [Any], jsonValue as? [String: Any], stringValue) {
84-
case (let .some(array), _, _):
85-
value = .list(try array.wrapInValue())
86-
case (_, let .some(dictionary), _):
87-
value = .structure(try dictionary.wrapInValue())
88-
case (_, _, let .some(unwrappedString)):
89-
switch (FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.date(from: unwrappedString),
90-
Int64(unwrappedString),
91-
Double(unwrappedString),
92-
Bool(unwrappedString)) {
93-
case (let .some(date), _, _, _):
94-
value = .date(date)
95-
case (_, let .some(int), _, _):
96-
value = .integer(int)
97-
case (_, _, let .some(double), _):
98-
value = .double(double)
99-
case (_, _, _, let .some(bool)):
100-
value = .boolean(bool)
101-
case (.none, .none, .none, .none):
102-
value = .string(unwrappedString)
103-
}
104-
case (.none, .none, .none):
105-
value = .null
106-
}
107-
108-
return .init(value: value, variant: value.description, reason: source.reason.rawValue)
109-
}
110-
}
111-
}
11+
extension RemoteConfigValue: RemoteConfigValueCompatible {}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
//
2+
// RemoteConfigValueCompatible+Extensions.swift
3+
//
4+
//
5+
// Created by Fumito Ito on 2024/01/25.
6+
//
7+
8+
import Foundation
9+
import FirebaseRemoteConfig
10+
import OpenFeature
11+
12+
extension RemoteConfigValueCompatible {
13+
var toBooleanEvaluation: ProviderEvaluation<Bool> {
14+
.init(value: boolValue, variant: "\(boolValue)", reason: source.reason.rawValue)
15+
}
16+
17+
var toStringEvaluation: ProviderEvaluation<String> {
18+
guard let value = stringValue else {
19+
return .init(value: "", variant: "", reason: Reason.staticReason.rawValue)
20+
}
21+
22+
return .init(value: value, variant: stringValue, reason: source.reason.rawValue)
23+
}
24+
25+
var toInt64Evaluation: ProviderEvaluation<Int64> {
26+
.init(value: numberValue.int64Value, variant: "\(numberValue.int64Value)", reason: source.reason.rawValue)
27+
}
28+
29+
var toDoubleEvaluation: ProviderEvaluation<Double> {
30+
.init(value: numberValue.doubleValue, variant: "\(numberValue.doubleValue)", reason: source.reason.rawValue)
31+
}
32+
33+
var toDateEvaluation: ProviderEvaluation<Date> {
34+
get throws {
35+
guard let dateString = stringValue else {
36+
throw OpenFeatureError.parseError(message: "指定されたキーから文字列を取得することができない")
37+
}
38+
39+
guard let date = FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.date(from: dateString) else {
40+
throw OpenFeatureError.parseError(message: "指定されたキーから取得した文字列を日付に変換することができない")
41+
}
42+
43+
return .init(value: date, variant: FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.string(from: date), reason: source.reason.rawValue)
44+
}
45+
}
46+
47+
var toValueArrayEvaluation: ProviderEvaluation<[Value]> {
48+
get throws {
49+
guard let jsonValue else {
50+
throw OpenFeatureError.parseError(message: "指定されたキーからJSONオブジェクトを取得することができない")
51+
}
52+
53+
guard let array = jsonValue as? [Any] else {
54+
throw OpenFeatureError.parseError(message: "指定されたキーから配列を取得することができない")
55+
}
56+
57+
let valuedArray = try array.wrapInValue()
58+
59+
return .init(value: valuedArray, variant: valuedArray.description, reason: source.reason.rawValue)
60+
}
61+
}
62+
63+
var toValueStructureEvaluation: ProviderEvaluation<[String: Value]> {
64+
get throws {
65+
guard let jsonValue else {
66+
throw OpenFeatureError.parseError(message: "指定されたキーからJSONオブジェクトを取得することができない")
67+
}
68+
69+
guard let dictionary = jsonValue as? [String: Any] else {
70+
throw OpenFeatureError.parseError(message: "指定されたキーからディクショナリを取得することができない")
71+
}
72+
73+
let valuedDictionary = try dictionary.wrapInValue()
74+
75+
return .init(value: valuedDictionary, variant: valuedDictionary.description, reason: source.reason.rawValue)
76+
}
77+
}
78+
79+
var toObjectEvaluation: ProviderEvaluation<Value> {
80+
get throws {
81+
let value: Value
82+
83+
switch (jsonValue as? [Any], jsonValue as? [String: Any], stringValue) {
84+
case (let .some(array), _, _):
85+
value = .list(try array.wrapInValue())
86+
case (_, let .some(dictionary), _):
87+
value = .structure(try dictionary.wrapInValue())
88+
case (_, _, let .some(unwrappedString)):
89+
switch (FirebaseRemoteConfigOpenFeatureProvider.dateFormatter.date(from: unwrappedString),
90+
Int64(unwrappedString),
91+
Double(unwrappedString),
92+
Bool(unwrappedString)) {
93+
case (let .some(date), _, _, _):
94+
value = .date(date)
95+
case (_, let .some(int), _, _):
96+
value = .integer(int)
97+
case (_, _, let .some(double), _):
98+
value = .double(double)
99+
case (_, _, _, let .some(bool)):
100+
value = .boolean(bool)
101+
case (.none, .none, .none, .none):
102+
value = .string(unwrappedString)
103+
}
104+
case (.none, .none, .none):
105+
value = .null
106+
}
107+
108+
return .init(value: value, variant: value.description, reason: source.reason.rawValue)
109+
}
110+
}
111+
}

0 commit comments

Comments
 (0)