type

Settings

@Js
const class Settings : Obj, Dict

Settings wraps a dict that maps tags to statically typed fields for extension settings. To use this API:

  1. Create subclass of Settings
  2. Annotate const instance fields with @Setting
  3. Create constructor with Dict and it-block callback

The following coercions are supported:

  • Int field from Number tag
  • Duration field from Number tag
  • Bool field from Marker tag

Example:

const class ExampleSettings : Settings
{
  static new wrap(Dict d, |Str|? onErr := null) { create(ExampleRec#, d, onErr) }

  new make(Dict d, |This| f) : super(d) { f(this) }

  @Setting const Int limit := 99

  @Setting const Duration timeout := 3sec
}

constructors

make

Sub constructor.

methods

create

Factory to create for given type and dict to wrap.

each

Iterate the wrapped dict tags

eachWhile

Iterate the wrapped dict tags until callback returns non-null

get

Get a tag from wrapped dict

has

Return if wrapped dict has given tag

isEmpty

Return if wrapped dict is empty

meta

Wrapped dict for this instance

missing

Return if wrapped dict is missing given tag

trap

Trap on the wrapped dict

Slot Details

create

static Settings create(Type type, Dict meta, |Str|? onErr := null)

Factory to create for given type and dict to wrap. Invalid tag values are logged to the given callback if provided.

each

virtual override Void each(|Obj,Str| f)

Iterate the wrapped dict tags

eachWhile

virtual override Obj? eachWhile(|Obj,Str->Obj?| f)

Iterate the wrapped dict tags until callback returns non-null

get

@Operator
virtual override Obj? get(Str n)

Get a tag from wrapped dict

has

virtual override Bool has(Str n)

Return if wrapped dict has given tag

isEmpty

virtual override Bool isEmpty()

Return if wrapped dict is empty

make

new make(Dict meta)

Sub constructor.

meta

Dict meta()

Wrapped dict for this instance

missing

virtual override Bool missing(Str n)

Return if wrapped dict is missing given tag

trap

virtual override Obj? trap(Str n, Obj?[]? a := null)

Trap on the wrapped dict