Module: Kdep::UserConfig

Defined in:
lib/kdep/user_config.rb

Overview

Per-user kdep config persisted at ~/.kdep/config.yml. Currently holds only Infisical settings (identity_id, host_api), but kept generic so other CLI-wide knobs can land here.

Constant Summary collapse

PATH =
File.expand_path("~/.kdep/config.yml").freeze

Class Method Summary collapse

Class Method Details

.get(*keys) ⇒ Object



16
17
18
# File 'lib/kdep/user_config.rb', line 16

def self.get(*keys)
  load.dig(*keys.map(&:to_s))
end

.loadObject



11
12
13
14
# File 'lib/kdep/user_config.rb', line 11

def self.load
  return {} unless File.exist?(PATH)
  YAML.safe_load(File.read(PATH)) || {}
end

.set(dotted_key, value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/kdep/user_config.rb', line 20

def self.set(dotted_key, value)
  keys = dotted_key.to_s.split(".")
  data = load
  cursor = data
  keys[0..-2].each do |k|
    cursor[k] = {} unless cursor[k].is_a?(Hash)
    cursor = cursor[k]
  end
  cursor[keys.last] = value
  write(data)
end

.write(data) ⇒ Object



32
33
34
35
36
# File 'lib/kdep/user_config.rb', line 32

def self.write(data)
  FileUtils.mkdir_p(File.dirname(PATH))
  File.write(PATH, data.to_yaml)
  PATH
end