How to use the routemaster.config.model.ContextNextStatesOption 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 all_destinations(self) -> Iterable[str]:
        """Returns the constant next state."""
        return [self.state]


class ContextNextStatesOption(NamedTuple):
    """Represents an option for a context conditional next state."""
    state: str
    value: Any


class ContextNextStates(NamedTuple):
    """Defined a choice based on a path in the given `label_context`."""
    path: str
    destinations: Iterable[ContextNextStatesOption]
    default: str  # noqa: E704 misidentified "multiple statements on one line"

    def next_state_for_label(self, label_context: 'Context') -> str:
        """Returns next state based on context value at `self.path`."""
        val = label_context.lookup(self.path.split('.'))
        for destination in self.destinations:
            if destination.value == val:
                return destination.state
        return self.default

    def all_destinations(self) -> Iterable[str]:
        """Returns all possible destination states."""
        return [x.state for x in self.destinations] + [self.default]


class NoNextStates(NamedTuple):
github thread / routemaster / routemaster / config / loader.py View on Github external
def _load_context_next_state_option(
    path: Path,
    yaml_option: Yaml,
) -> ContextNextStatesOption:
    return ContextNextStatesOption(
        state=yaml_option['state'],
        value=yaml_option['value'],
    )