Class: Tasku::Config
- Inherits:
-
Object
- Object
- Tasku::Config
- Defined in:
- lib/tasku/config.rb
Constant Summary collapse
- CONFIG_PATH =
File.join(Dir.home, ".tasku", "config.json")
- VALID_KEYS =
{ "list_spacing" => { values: %w[compact spacious], default: "compact", description: "Row spacing in task list" }, "bar_project" => { values: %w[on off], default: "on", description: "Show project colour segment in row bar" }, "bar_priority" => { values: %w[on off], default: "on", description: "Show priority colour segment in row bar" }, "bar_status" => { values: %w[on off], default: "on", description: "Show status colour segment in row bar" } }.freeze
Class Method Summary collapse
Class Method Details
.all ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/tasku/config.rb', line 44 def self.all return {} unless File.exist?(CONFIG_PATH) JSON.parse(File.read(CONFIG_PATH)) rescue JSON::ParserError {} end |
.get(key) ⇒ Object
33 34 35 |
# File 'lib/tasku/config.rb', line 33 def self.get(key) all[key] || VALID_KEYS.dig(key, :default) end |
.set(key, value) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/tasku/config.rb', line 37 def self.set(key, value) current = all current[key] = value FileUtils.mkdir_p(File.dirname(CONFIG_PATH)) File.write(CONFIG_PATH, JSON.pretty_generate(current)) end |