Lookups

Description

Lookups are lists of constants that are used to restrict the value of a class property. Class properties that are a type of lookup can only contain a value that is included in the list of entry names from the lookup.

Unlike class definitions, lookup definitions are very basic and do not contain methods, event handlers or migration blocks.

Programmatic Declaration

[com.appirator.core.]reflect.Lookup
  extends [com.appirator.core.]reflect.ModuleNamed
  extends [com.appirator.core.]Object
  parent [com.appirator.core.]reflect.Module

Properties

name optional (when using Git sync)

The name of the lookup in its associated module. This is taken from the file name by default if the lookup is being imported as a file. It can be prefixed with the path name of the file when imported as a file where the path segments are separated with a dot. Similarly, if created object over a REST interface dot notation is permitted. This must be unique within the module.

default optional

The default value to use in place of the property when it has no value assigned to it. This must be one of the entry names from the lookup. If the property is an array of lookup values, then this can be a list of unique entry names from the lookup.

If the default is not set, it may be set directly on the class property using the default property of the class property. The use of default on the class property always overrides the default value on the lookup itself.

If neither the lookup default or the class property default is used, and no value is assigned to the property, then the property will remain unset.

entries

An array of lookup entries. Each entry can have the following properties.

Entry Properties

name

The lookup entry name. These must be unique within the lookup.

Lookup entry names must begin with a character between A-Z and can then contain any characters A-Z, 0-9 and underscore.

changeTo optional

The array of lookup names that the property can change to if the property currently holds the value specified in name. If an attempt is made to set the value of the property to a value outside of this list, then an error will occur.

If this property is not set, then there is no restriction on what the property can be set to as long as the value is one of the lookup entry names from the lookup.

Example

[AccountStatus.lup.yaml]

default: PENDING
entries:

  # The initial state of the account.
  - name: PENDING
    changeTo: ACTIVE INACTIVE

  # The account is active. The only change in this state is a change to an
  # INACTIVE state.
  - name: ACTIVE
    changeTo: INACTIVE

  # The account is inactive. The only change in this state is a change to an
  # ACTIVE state.
  - name: INACTIVE
    changeTo: ACTIVE