Module: Wokku::Config
- Defined in:
- lib/wokku/config.rb
Constant Summary collapse
- DEFAULT_DIR =
File.("~/.wokku")
Class Method Summary collapse
- .api_token ⇒ Object
- .api_url ⇒ Object
- .dir ⇒ Object
- .file ⇒ Object
- .load ⇒ Object
- .save(data) ⇒ Object
Class Method Details
.api_token ⇒ Object
37 38 39 |
# File 'lib/wokku/config.rb', line 37 def api_token load["token"] || ENV["WOKKU_API_TOKEN"] end |
.api_url ⇒ Object
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 |
.dir ⇒ Object
12 13 14 |
# File 'lib/wokku/config.rb', line 12 def dir ENV["WOKKU_CONFIG_DIR"] || DEFAULT_DIR end |
.file ⇒ Object
16 17 18 |
# File 'lib/wokku/config.rb', line 16 def file File.join(dir, "config.json") end |
.load ⇒ Object
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 |