4
4
5
5
namespace Elastic . Documentation . Configuration . Builder ;
6
6
7
- public class FeatureFlags ( Dictionary < string , bool > featureFlags )
7
+ public class FeatureFlags ( Dictionary < string , bool > initFeatureFlags )
8
8
{
9
- public bool IsPrimaryNavEnabled => IsEnabled ( "primary-nav" ) ;
10
- public bool IsVersionDropdownEnabled => IsEnabled ( "version-dropdown" ) ;
9
+ private readonly Dictionary < string , bool > _featureFlags = new ( initFeatureFlags ) ;
10
+
11
+ public void Set ( string key , bool value )
12
+ {
13
+ var normalizedKey = key . ToLowerInvariant ( ) . Replace ( '_' , '-' ) ;
14
+ _featureFlags [ normalizedKey ] = value ;
15
+ }
16
+
17
+ public bool PrimaryNavEnabled
18
+ {
19
+ get => IsEnabled ( "primary-nav" ) ;
20
+ set => _featureFlags [ "primary-nav" ] = value ;
21
+ }
22
+
23
+ public bool VersionDropdownEnabled
24
+ {
25
+ get => IsEnabled ( "version-dropdown" ) ;
26
+ set => _featureFlags [ "version-dropdown" ] = value ;
27
+ }
28
+
11
29
private bool IsEnabled ( string key )
12
30
{
13
31
var envKey = $ "FEATURE_{ key . ToUpperInvariant ( ) . Replace ( '-' , '_' ) } ";
@@ -18,6 +36,7 @@ private bool IsEnabled(string key)
18
36
// if the env var is set but not a bool, we treat it as enabled
19
37
return true ;
20
38
}
21
- return featureFlags . TryGetValue ( key , out var value ) && value ;
39
+
40
+ return _featureFlags . TryGetValue ( key , out var value ) && value ;
22
41
}
23
42
}
0 commit comments