assignAbilityToActions static method

Map<String, dynamic> assignAbilityToActions(
  1. String ability,
  2. List<String> actions, {
  3. Map limits = const {},
})

Implementation

static Map<String, dynamic> assignAbilityToActions(
  String ability,
  List<String> actions, {
  Map limits = const {},
}) {
  final sortedActions = List<String>.from(actions)
    ..sort((a, b) => a.compareTo(b));

  Map<String, dynamic> abilities = {};
  for (var method in sortedActions) {
    abilities['$ability/$method'] = [
      ...(abilities['$ability/$method'] ?? []),
      limits,
    ];
  }

  return Map<String, dynamic>.fromEntries(abilities.entries);
}