Module: Wokku::Config

Defined in:
lib/wokku/config.rb

Constant Summary collapse

DEFAULT_DIR =
File.expand_path("~/.wokku")

Class Method Summary collapse

Class Method Details

.api_tokenObject



37
38
39
# File 'lib/wokku/config.rb', line 37

def api_token
  load["token"] || ENV["WOKKU_API_TOKEN"]
end

.api_urlObject



33
34
35
# File 'lib/wokku/config.rb', line 33

def api_url
  load["api_url"] || ENV["WOKKU_API_URL"] || "https://wokku.cloud/api/v1"
end

.dirObject



12
13
14
# File 'lib/wokku/config.rb', line 12

def dir
  ENV["WOKKU_CONFIG_DIR"] || DEFAULT_DIR
end

.fileObject



16
17
18
# File 'lib/wokku/config.rb', line 16

def file
  File.join(dir, "config.json")
end

.loadObject



20
21
22
23
24
25
# File 'lib/wokku/config.rb', line 20

def load
  return {} unless File.exist?(file)
  JSON.parse(File.read(file))
rescue StandardError
  {}
end

.save(data) ⇒ Object



27
28
29
30
31
# File 'lib/wokku/config.rb', line 27

def save(data)
  FileUtils.mkdir_p(dir)
  File.write(file, JSON.pretty_generate(data))
  File.chmod(0600, file)
end