Module: TUI::Settings
- Defined in:
- lib/tui/settings.rb
Overview
TUI-specific configuration backed by ~/.anima/tui.toml.
Zero Rails dependency — the TUI is a standalone client process.
Accessors are generated automatically from the template TOML file. Convention: method name = section_key (e.g. [hud] min_width →hud_min_width). To add a setting, add the key to tui.toml — the accessor appears automatically.
Settings are loaded once at startup. Restart the TUI to pick up changes — it’s a thin client, the brain won’t notice.
Defined Under Namespace
Classes: MissingConfigError, MissingSettingError
Constant Summary collapse
- DEFAULT_PATH =
File.("~/.anima/tui.toml")
- TEMPLATE_PATH =
File.("../../../templates/tui.toml", __FILE__)
- TEMPLATE =
TomlRB.load_file(TEMPLATE_PATH)
Class Method Summary collapse
-
.config_path ⇒ String
Active config file path.
-
.config_path=(path) ⇒ Object
Override config file path (for testing).
-
.load! ⇒ Object
Parses the config file and populates all setting ivars.
-
.load_defaults! ⇒ Object
Populates ivars from the cached TEMPLATE hash without touching disk.
-
.reset! ⇒ Object
Restores template defaults and clears the path override.
Class Method Details
.config_path ⇒ String
Returns active config file path.
48 49 50 |
# File 'lib/tui/settings.rb', line 48 def config_path @config_path || DEFAULT_PATH end |
.config_path=(path) ⇒ Object
Override config file path (for testing). Triggers a load so the new config takes effect immediately.
42 43 44 45 |
# File 'lib/tui/settings.rb', line 42 def config_path=(path) @config_path = path load! if path end |
.load! ⇒ Object
Parses the config file and populates all setting ivars.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/tui/settings.rb', line 72 def load! path = config_path unless File.exist?(path) raise MissingConfigError, "TUI config file not found: #{path}. Run `anima install` to create it." end parsed = TomlRB.load_file(path) TEMPLATE.each do |section, keys| keys.each_key do |key| value = parsed.dig(section, key) if value.nil? raise MissingSettingError, "[#{section}] #{key} is not set in #{path}. Run `anima update` to add missing settings." end instance_variable_set(:"@#{section}_#{key}", value) end end end |
.load_defaults! ⇒ Object
Populates ivars from the cached TEMPLATE hash without touching disk. Intended for test suites that want template defaults without paying the TOML parse cost for every example.
62 63 64 65 66 |
# File 'lib/tui/settings.rb', line 62 def load_defaults! TEMPLATE.each do |section, keys| keys.each { |key, value| instance_variable_set(:"@#{section}_#{key}", value) } end end |
.reset! ⇒ Object
Restores template defaults and clears the path override. Useful in test teardown.
54 55 56 57 |
# File 'lib/tui/settings.rb', line 54 def reset! @config_path = nil load_defaults! end |