Skip to content

Commit 2c7f0cf

Browse files
refactor(policy): enhance PolicyManager by optimizing JSON parsing with a mapped policy structure
1 parent 70aa451 commit 2c7f0cf

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

lib/src/core/policy_manager.dart

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,18 @@ class PolicyManager extends ChangeNotifier {
7979
operation: 'policy_manager_initialize',
8080
);
8181

82+
final policyMap = jsonPolicies.map(
83+
(key, value) => MapEntry(
84+
key,
85+
Policy(
86+
roleName: key,
87+
allowedContent: value as List<String>,
88+
).toJson(),
89+
),
90+
);
91+
8292
_policies = JsonHandler.parseMap(
83-
jsonPolicies,
93+
policyMap,
8494
(json) => Policy.fromJson(json),
8595
context: 'policy_manager',
8696
allowPartialSuccess:

test/flutter_policy_engine_test.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,4 @@ import 'package:flutter_test/flutter_test.dart';
22

33
import 'package:flutter_policy_engine/flutter_policy_engine.dart';
44

5-
void main() {
6-
test('adds one to input values', () {
7-
final calculator = Calculator();
8-
expect(calculator.addOne(2), 3);
9-
expect(calculator.addOne(-7), -6);
10-
expect(calculator.addOne(0), 1);
11-
});
12-
}
5+
void main() {}

0 commit comments

Comments
 (0)