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.
-
.reset! ⇒ Object
Clears all loaded settings and resets to default path.
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.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/tui/settings.rb', line 65 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 |
.reset! ⇒ Object
Clears all loaded settings and resets to default path. Useful in test teardown.
54 55 56 57 58 59 |
# File 'lib/tui/settings.rb', line 54 def reset! @config_path = nil TEMPLATE.each do |section, keys| keys.each_key { |key| instance_variable_set(:"@#{section}_#{key}", nil) } end end |