Class: Vaultez::Config
- Inherits:
-
Object
- Object
- Vaultez::Config
- Defined in:
- lib/vaultez/config.rb
Constant Summary collapse
- CONFIG_PATH =
File.("~/.vaultez/config.yml")
Class Method Summary collapse
- .api_url ⇒ Object
- .clear ⇒ Object
- .default_company ⇒ Object
- .delete(key) ⇒ Object
- .get(key) ⇒ Object
- .read ⇒ Object
- .set(key, value) ⇒ Object
- .token ⇒ Object
- .write(data) ⇒ Object
Class Method Details
.api_url ⇒ Object
32 33 34 |
# File 'lib/vaultez/config.rb', line 32 def self.api_url get("api_url") || "https://vaultez.app" end |
.clear ⇒ Object
24 25 26 |
# File 'lib/vaultez/config.rb', line 24 def self.clear FileUtils.rm_f(CONFIG_PATH) end |
.default_company ⇒ Object
36 37 38 |
# File 'lib/vaultez/config.rb', line 36 def self.default_company get("default_company") end |
.delete(key) ⇒ Object
18 19 20 21 22 |
# File 'lib/vaultez/config.rb', line 18 def self.delete(key) data = read data.delete(key.to_s) write(data) end |
.get(key) ⇒ Object
8 9 10 |
# File 'lib/vaultez/config.rb', line 8 def self.get(key) read[key.to_s] end |
.read ⇒ Object
42 43 44 45 |
# File 'lib/vaultez/config.rb', line 42 def self.read return {} unless File.exist?(CONFIG_PATH) YAML.safe_load(File.read(CONFIG_PATH)) || {} end |
.set(key, value) ⇒ Object
12 13 14 15 16 |
# File 'lib/vaultez/config.rb', line 12 def self.set(key, value) data = read data[key.to_s] = value write(data) end |
.token ⇒ Object
28 29 30 |
# File 'lib/vaultez/config.rb', line 28 def self.token get("token") end |
.write(data) ⇒ Object
47 48 49 50 |
# File 'lib/vaultez/config.rb', line 47 def self.write(data) FileUtils.mkdir_p(File.dirname(CONFIG_PATH)) File.write(CONFIG_PATH, data.to_yaml) end |