class

Superconf::Option(T)

Inherits Superconf::AbstractOption < Reference < Object

One registered, typed configuration option.

T may be Bool, Int32, Int64, Float64, String, Char, Time::Span, or any Enum (including @[Flags] enums). Any other type is supported by passing an explicit parse: proc to register.

Constructors

new(key : String, default : T, *, explicit_env : String | Nil, cli : String, group : String, description : String, parse : Proc(String, T) | Nil = nil, validate : Proc(T, Bool) | Nil = nil)
Source

Instance methods

bool?

Is the value type Bool? Governs --flag / --no-flag generation.

Source
build_alias(key : String, *, explicit_env : String | Nil, cli : String, group : String, description : String) : AbstractOption

Build an alias of this option, registered under key with its own env/CLI/group surfaces but sharing this option's value. Used by Superconf.register_alias.

Source
default
Source
default=(value : T)

Change the recorded default (used by Superconf.set_default). Doesn't itself change the effective value; the caller also sets at Default precedence so config/env/CLI/runtime still win. Validated here because a set at Default precedence is skipped once a higher source has won, so an invalid default could otherwise slip in unvalidated and later surface (e.g. via default_string, or once the higher source is cleared).

Source
default_string

The registered default, rendered as a string.

Source
emit_json(json : JSON::Builder) : Nil

Emit the current value as a native JSON value.

Source
emit_yaml(yaml : YAML::Builder) : Nil

Numeric/bool values are emitted as plain scalars (0.2, true) so they re-read with their native YAML types. Strings and enums are force-quoted: an unquoted yes, no, null or 123 would otherwise be re-parsed by YAML 1.1 as a bool/nil/int and corrupt the value on reload. stringify already normalizes Time::Span to seconds.

Source
set(value : T, source : Source = Source::Runtime, origin : String = "API") : Nil

Typed assignment. Applies only if source is at least as authoritative as the source of the current value (see Source); a value that wins must also pass the option's validate predicate, if any.

Source
set_from_string(str : String, source : Source, origin : String) : Nil

Parse str and store it, honoring precedence (see Source).

Source
stringify

Current value rendered as the string used across env/CLI/config/dumps.

Source
value
Source