How to use the routemaster.config.model.MetadataTrigger function in routemaster

To help you get started, we’ve selected a few routemaster examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thread / routemaster / routemaster / config / model.py View on Github external
def applies(path: Sequence[str], d: Dict[str, Any]) -> bool:
            component, path = path[0], path[1:]
            if component in d:
                if path:
                    return applies(path, d[component])
                return True
            return False
        return applies(self.metadata_path.split('.'), update)


@dataclass
class OnEntryTrigger:
    """Trigger on entry to a given gate."""


Trigger = Union[TimeTrigger, IntervalTrigger, MetadataTrigger, OnEntryTrigger]


class ConstantNextState(NamedTuple):
    """Defines a constant choice, always chooses `state`."""
    state: str

    def next_state_for_label(self, label_context: Any) -> str:
        """Returns the constant next state."""
        return self.state

    def all_destinations(self) -> Iterable[str]:
        """Returns the constant next state."""
        return [self.state]


class ContextNextStatesOption(NamedTuple):
github thread / routemaster / routemaster / config / model.py View on Github external
def metadata_triggers(self) -> List[MetadataTrigger]:
        """Return a list of the metadata triggers for this state."""
        return [x for x in self.triggers if isinstance(x, MetadataTrigger)]
github thread / routemaster / routemaster / config / loader.py View on Github external
def _load_metadata_trigger(path: Path, yaml_trigger: Yaml) -> MetadataTrigger:
    metadata_path = yaml_trigger['metadata']
    if not RE_PATH.match(metadata_path):  # pragma: no branch
        raise ConfigError(  # pragma: no cover
            f"Metadata trigger '{metadata_path}' at path {'.'.join(path)} is "
            f"not a valid dotted path.",
        )
    return MetadataTrigger(metadata_path=metadata_path)