Skip to content

Commit e3d7278

Browse files
authored
Introduce LocalConfigOverrides for settings. (#10586)
1 parent fe80522 commit e3d7278

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
//
2+
// Copyright 2022 Google LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
import Foundation
17+
18+
/// Protoco defining the loval override values for the SDK settings.
19+
protocol SessionLocalConfigProtocol {
20+
/// Session enabled flag value.
21+
var sessionEnabled: Bool? { get }
22+
23+
/// Session timeout flag value.
24+
var sessionTimeout: TimeInterval? { get }
25+
26+
/// Session timeout flag value.
27+
var sessionSamplingRate: Double? { get }
28+
}
29+
30+
/// Class that manages the local overrides configs related to the library.
31+
class SessionLocalConfig: SessionLocalConfigProtocol {
32+
static let PlistKey_sessions_enabled = "FirebaseSessionsEnabled"
33+
static let PlistKey_sessions_timeout = "FirebaseSessionsTimeout"
34+
static let PlistKey_sessions_samplingRate = "FirebaseSessionsSampingRate"
35+
36+
var sessionEnabled: Bool? {
37+
return plistValueForConfig(configName: SessionLocalConfig.PlistKey_sessions_enabled) as? Bool
38+
}
39+
40+
var sessionTimeout: TimeInterval? {
41+
return
42+
plistValueForConfig(configName: SessionLocalConfig.PlistKey_sessions_timeout) as? TimeInterval
43+
}
44+
45+
var sessionSamplingRate: Double? {
46+
return
47+
plistValueForConfig(configName: SessionLocalConfig.PlistKey_sessions_samplingRate) as? Double
48+
}
49+
50+
private func plistValueForConfig(configName: String) -> Any? {
51+
return Bundle.main.value(forKey: configName)
52+
}
53+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Copyright 2022 Google LLC
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
import Foundation
17+
@testable import FirebaseSessions
18+
19+
class MockSessionLocalConfig: SessionLocalConfigProtocol {
20+
var sessionEnabled: Bool?
21+
22+
var sessionTimeout: TimeInterval?
23+
24+
var sessionSamplingRate: Double?
25+
}

0 commit comments

Comments
 (0)