-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenvironment.dart
More file actions
58 lines (50 loc) · 1.46 KB
/
environment.dart
File metadata and controls
58 lines (50 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import 'dart:io';
/// Wraps access to Environment variables
/// Allows faking for testing
class Environment {
static const String raygunAppIdKey = 'RAYGUN_APP_ID';
static const String raygunTokenKey = 'RAYGUN_TOKEN';
static const String raygunApiKeyKey = 'RAYGUN_API_KEY';
final String? raygunAppId;
final String? raygunToken;
final String? raygunApiKey;
static Environment? _instance;
/// Singleton instance access
/// Will init if not already
static Environment get instance {
_instance ??= Environment._init();
return _instance!;
}
/// For testing purposes
static void setInstance(Environment instance) {
_instance = instance;
}
/// Create custom instance
Environment({
required this.raygunAppId,
required this.raygunToken,
required this.raygunApiKey,
});
String? operator [](String key) {
switch (key) {
case raygunAppIdKey:
return raygunAppId;
case raygunTokenKey:
return raygunToken;
case raygunApiKeyKey:
return raygunApiKey;
default:
throw ArgumentError('Unknown environment variable: $key');
}
}
factory Environment._init() {
final raygunAppId = Platform.environment[raygunAppIdKey];
final raygunToken = Platform.environment[raygunTokenKey];
final raygunApiKey = Platform.environment[raygunApiKeyKey];
return Environment(
raygunAppId: raygunAppId,
raygunToken: raygunToken,
raygunApiKey: raygunApiKey,
);
}
}