Class: Vaultez::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/vaultez/config.rb

Constant Summary collapse

CONFIG_PATH =
File.expand_path("~/.vaultez/config.yml")

Class Method Summary collapse

Class Method Details

.api_urlObject



32
33
34
# File 'lib/vaultez/config.rb', line 32

def self.api_url
  get("api_url") || "https://vaultez.app"
end

.clearObject



24
25
26
# File 'lib/vaultez/config.rb', line 24

def self.clear
  FileUtils.rm_f(CONFIG_PATH)
end

.default_companyObject



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

.readObject



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

.tokenObject



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