ConfigService class
Central configuration service for Neomage.
Manages layered configuration across ConfigScope.global, ConfigScope.project, and ConfigScope.session scopes. Values set in a narrower scope override broader ones (session > project > global > default).
Usage:
final config = ConfigService();
await config.loadFromFile(config.getConfigPath(scope: ConfigScope.global));
config.loadFromEnv();
final model = config.get<String>(ConfigKeys.model);
config.watch<String>(ConfigKeys.model).listen((v) => print('model=$v'));
Constructors
Properties
-
changes
→ Stream<
ConfigChangeEvent> -
Stream of all configuration change events.
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
diff(
ConfigScope scope1, ConfigScope scope2) → List< ConfigDiff> - Compare configuration between two scopes and return the differences.
-
dispose(
) → void - Release resources.
-
exportConfig(
{ConfigScope? scope, String format = 'json'}) → String - Export configuration to a JSON or YAML string.
-
get<
T> (String key, {ConfigScope? scope, T? defaultValue}) → T -
Retrieve a typed value for
key. -
getAll(
{ConfigScope? scope}) → Map< String, dynamic> -
Return all key-value pairs for
scope(defaults to merged view). -
getConfigPath(
{ConfigScope scope = ConfigScope.global, String? projectRoot}) → String - Return the canonical file path for a configuration scope.
-
getEntry<
T> (String key, {ConfigScope? scope}) → ConfigEntry< T> ? - Build a ConfigEntry for inspection of a single key.
-
getSource(
String key, {ConfigScope scope = ConfigScope.global}) → ConfigSource? - Return the ConfigSource for a specific key within a scope.
-
has(
String key, {ConfigScope? scope}) → bool -
Whether
keyexists inscope(or any scope ifscopeis null). -
importFromNeomage(
) → Future< bool> -
Attempt to migrate settings from an existing Neomage installation at
~/.neomage/. -
loadFromEnv(
{Map< String, String> ? overrideEnv}) → void - Read well-known environment variables and store them in the global scope.
-
loadFromFile(
String path, {ConfigScope scope = ConfigScope.global}) → Future< bool> -
Load configuration from a JSON file at
pathinto the givenscope. -
merge(
Map< String, dynamic> overrides, {ConfigScope scope = ConfigScope.session}) → void -
Merge
overridesinto the givenscope. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
remove(
String key, {ConfigScope scope = ConfigScope.session}) → void -
Remove a key from the given
scope. -
reset(
{ConfigScope? scope, String? key}) → void - Reset configuration.
-
saveToFile(
String path, {ConfigScope scope = ConfigScope.global}) → Future< void> -
Save configuration for
scopeto a JSON file atpath. -
set<
T> (String key, T value, {ConfigScope scope = ConfigScope.session}) → void -
Set a typed value for
keyin the givenscope(defaults to session). -
toString(
) → String -
A string representation of this object.
inherited
-
tryGet<
T> (String key, {ConfigScope? scope}) → T? -
Try to get a value, returning
nullinstead of throwing. -
validate(
) → ConfigValidation - Validate the merged configuration using built-in rules.
-
watch<
T> (String key) → Stream< T> -
Observe changes to a specific
key, emitting the new value whenever it changes in any scope.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited