casesOfRole method

List<ContractCase> casesOfRole(
  1. Role<Object> role
)

The cases of role: for each of its providers and each subset of the roles the role uses, the largest first, one case for each combination of a provider of each role the provider requires and of each role of the subset, named as the cases of casesOfModule are, such as analytics by firebase_analytics (get_it) with di. As for a module, a combination whose providers cannot be in one app with the provider is left out, such as another provider of a role that the provider provides too, unless no combination of the subset can.

After them come the cases of the mode options of role (see RoleOption.mode): for each provider and each value of such an option after the first, the first case of the provider, which has every role that the role uses, once more with that value among its ContractCase.roleOptions, named <case> --<option>=<value>, such as clock by sundial --clock-hours=12. The cases before them leave the option out, so their apps have its first value. A role with two such options gets a case for each value of each, not for each pair of them. An option that roleOptions give a value has no such cases.

Implementation

List<ContractCase> casesOfRole(Role role) {
  final used = [
    for (final other in role.uses)
      if (registry.providersOf(other).isNotEmpty) other,
  ];
  final byProvider = [
    for (final provider in registry.providersOf(role))
      [
        for (final subset in _subsets(used))
          for (final picks in _fittingPicks(
            _withDependencies(provider),
            _picksOf([...provider.descriptor.effectiveRequires, ...subset]),
          ))
            _case(
              _caseName(
                '${role.id} by ${provider.descriptor.id}',
                picks,
                subset,
              ),
              [provider.descriptor.id],
              picks: {...picks, role: provider.descriptor.id},
              present: subset,
            ),
      ],
  ];
  final modes = _openModesOf([role]);
  return [
    for (final cases in byProvider) ...cases,
    // The subsets come the largest first, so the first case of a provider
    // has every role that the role uses.
    for (final cases in byProvider)
      for (final option in modes)
        for (final value in option.allowed!.skip(1))
          _withModes(cases.first, {option.name: value}),
  ];
}