class

AmebaConfig::Config

Inherits Reference < Object

In-memory representation of an .ameba.yml configuration. The model is split between rules (keys matching Group/Name) and extras (any other top-level keys, preserved verbatim on write).

Constructors

load(path : String) : Config
Source
parse(text : String) : Config

Build a Config from raw YAML text.

Source

Class methods

generate_template(io : IO, catalog : Catalog) : Nil

Write a fully-commented template containing every rule the catalog knows about, with its description and default settings. The output is valid YAML (all empty lines or comments), so reading it back yields an empty config. The intended workflow is for a user to uncomment the rules and settings they want to customise.

Source
load?(path : String) : Config | Nil
Source

Instance methods

add_to_extra_list!(key : String, values : Array(String)) : Nil

Append values to a top-level extras list, skipping duplicates.

Source
clear_extra!(key : String) : Nil

Remove a top-level extras entry entirely.

Source
disable!(name : String, catalog : Catalog) : Nil
Source
enable!(name : String, catalog : Catalog) : Nil

Apply enable: ensure the rule has Enabled: true.

Source
extra_list(key : String) : Array(String)

Read a top-level extras entry as a list of strings. Returns an empty array if the entry is missing or not a list.

Source
extras
Source
fill_defaults_for_present_rules!(catalog : Catalog) : Nil

Add missing settings from catalog defaults into every rule already present in this config. Used by update so that any rule we keep has all of its settings spelled out.

Source
has_rule?(name : String) : Bool
Source
matches_defaults?(rule_def : Rule, settings : Hash(String, YAML::Any)) : Bool

True when every entry in settings matches rule_def's defaults exactly, with no extra keys. An empty settings hash also counts as matching when the rule has no defaults; an empty settings against a rule that does have defaults returns false (the user removed values without specifying alternatives).

Source
merge_template!(template : Config) : Nil

Merge a template config into self: add rules missing from self, and within each existing rule add any settings that are missing.

Source
remove_from_extra_list!(key : String, values : Array(String)) : Nil

Remove the given values from a top-level extras list.

Source
render(io : IO, catalog : Catalog, warnings : Array(String) | Nil = nil, header : String | Nil = nil, empty_note : String | Nil = nil) : Nil

Render the config to io with descriptions as comments, rules in alphabetical order, and rules whose settings are identical to the catalog defaults omitted entirely. extras are written first, verbatim.

header is emitted at the top (as-is, with its own trailing newline). When the rest of the output would be empty and empty_note is given, the note is emitted in place of the body so the file isn't blank.

Source
render(catalog : Catalog, warnings : Array(String) | Nil = nil, header : String | Nil = nil, empty_note : String | Nil = nil) : String
Source
reset!(name : String, key : String, catalog : Catalog) : Nil

Remove a setting override so the rule's default applies again. If after removal the rule has no remaining settings (or only defaults), the rule entry itself is dropped on the next save by the omit-defaults logic.

Source
rule_settings(name : String) : Hash(String, YAML::Any)

Returns a hash of the named rule's settings, creating an empty entry if missing.

Source
rules

rule name => ordered map of setting => value

Source
save(path : String, catalog : Catalog, warnings : Array(String) | Nil = nil, header : String | Nil = nil, empty_note : String | Nil = nil) : Nil

Save the config to path, atomically. See #render for header and empty_note semantics.

Source
set!(name : String, key : String, value : YAML::Any, catalog : Catalog) : Nil
Source
set_extra_list!(key : String, values : Array(String)) : Nil

Replace the top-level extras entry with the given list of strings.

Source