1 module hunt.framework.application.HostEnvironment;
2 
3 import hunt.framework.Init;
4 
5 import std.process;
6 import std.range;
7 
8 // 
9 enum ENV_APP_NAME = "APP_NAME";
10 enum ENV_APP_VERSION = "APP_VERSION";
11 enum ENV_APP_ENV = "APP_ENV";
12 enum ENV_APP_LANG = "APP_LANG";
13 enum ENV_APP_KEY = "APP_KEY";
14 enum ENV_APP_BASE_PATH = "APP_BASE_PATH";
15 enum ENV_CONFIG_BASE_PATH = "CONFIG_BASE_PATH";
16 
17 
18 /**
19  * 
20  */
21 class HostEnvironment {
22     string _name = DEFAULT_RUNTIME_ENVIRONMENT;
23     string _configPath = DEFAULT_CONFIG_LACATION;
24 
25     this() {
26         string value = environment.get("HUNT_ENV", "");
27         if(value.empty) {
28             value = environment.get(ENV_APP_ENV, "");
29         }
30 
31         if(!value.empty) {
32             _name = value;
33         }
34     }
35 
36     string name() {
37         return _name;
38     }
39 
40     HostEnvironment name(string value) {
41         _name = value;
42         return this;
43     }
44 
45     string configPath() {
46         return _configPath;
47     }
48 
49     HostEnvironment configPath(string value) {
50         if (value[$ - 1] == '/')
51             _configPath = value;
52         else
53             _configPath = value ~ "/";        
54         return this;
55     }
56 
57     bool isProduction() {
58         return _name == "production";
59     }
60 
61     bool isDevelopment() {
62         return _name == "development" || _name == DEFAULT_RUNTIME_ENVIRONMENT;
63     }
64 
65     bool isTest() {
66         return _name == "test";
67     }
68 
69     bool isStaging() {
70         return _name == "staging";
71     }
72 
73     bool isEnvironment(string name) {
74         return _name == name;
75     }    
76 
77 }