Skip to content

Commit 543aa90

Browse files
authored
refactor: refactored the function_name (#52)
1 parent d3f8fe2 commit 543aa90

File tree

4 files changed

+22
-23
lines changed

4 files changed

+22
-23
lines changed

lib/src/enforcer.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -44,26 +44,26 @@ class Enforcer extends ManagementEnforcer {
4444

4545
Enforcer._();
4646

47-
factory Enforcer.fromModelPathAndPolicyFile(
47+
factory Enforcer.initWithFile(
4848
String modelPath,
4949
String policyFile,
5050
) {
5151
final fileAdapter = FileAdapter(policyFile);
52-
return Enforcer.fromModelPathAndAdapter(modelPath, fileAdapter);
52+
return Enforcer.initWithAdapter(modelPath, fileAdapter);
5353
}
5454

55-
factory Enforcer.fromModelPathAndAdapter(
55+
factory Enforcer.initWithAdapter(
5656
String modelPath,
5757
Adapter adapter,
5858
) {
5959
final model = Model();
6060
model.loadModel(modelPath);
61-
final enf = Enforcer.fromModelAndAdapter(model, adapter);
61+
final enf = Enforcer.initWithModelAndAdapter(model, adapter);
6262
enf.modelPath = modelPath;
6363
return enf;
6464
}
6565

66-
factory Enforcer.fromModelAndAdapter(Model model, [Adapter? adapter]) {
66+
factory Enforcer.initWithModelAndAdapter(Model model, [Adapter? adapter]) {
6767
final _enforcer = Enforcer._();
6868
_enforcer.model = model;
6969
_enforcer.fm = FunctionMap.loadFunctionMap();

test/enforcer_test.dart

+14-14
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ void main() {
5555

5656
group('test enforcer initialization with adapter', () {
5757
var adapter = FileAdapter('casbin_examples/basic_policy.csv');
58-
var e = Enforcer.fromModelPathAndAdapter(
59-
'casbin_examples/basic_model.conf', adapter);
58+
var e =
59+
Enforcer.initWithAdapter('casbin_examples/basic_model.conf', adapter);
6060

6161
testEnforce('test 1', e, 'alice', 'data1', 'read', true);
6262
testEnforce('test 2', e, 'alice', 'data1', 'write', false);
@@ -145,7 +145,7 @@ void main() {
145145
m.addDef('e', 'e', 'some(where (p.eft == allow))');
146146
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
147147

148-
var e = Enforcer.fromModelAndAdapter(m);
148+
var e = Enforcer.initWithModelAndAdapter(m);
149149

150150
e.addPermissionForUser('alice', ['data1', 'invalid']);
151151

@@ -160,7 +160,7 @@ void main() {
160160
m.addDef('e', 'e', 'some(where (p.eft == allow))');
161161
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
162162

163-
var e = Enforcer.fromModelAndAdapter(m);
163+
var e = Enforcer.initWithModelAndAdapter(m);
164164

165165
e.addPermissionForUser('alice', ['data1', 'read']);
166166
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -188,7 +188,7 @@ void main() {
188188

189189
var a = FileAdapter('casbin_examples/keymatch_policy.csv');
190190

191-
var e = Enforcer.fromModelAndAdapter(m, a);
191+
var e = Enforcer.initWithModelAndAdapter(m, a);
192192

193193
testEnforce('test 1', e, 'alice', '/alice_data/resource1', 'GET', true);
194194
testEnforce('test 2', e, 'alice', '/alice_data/resource1', 'POST', true);
@@ -223,7 +223,7 @@ void main() {
223223

224224
var a = FileAdapter('casbin_examples/keymatch_policy.csv');
225225

226-
var e = Enforcer.fromModelAndAdapter(m, a);
226+
var e = Enforcer.initWithModelAndAdapter(m, a);
227227

228228
testEnforce('test 1', e, 'alice', '/alice_data/resource2', 'POST', true);
229229
});
@@ -257,7 +257,7 @@ void main() {
257257
m.addDef('e', 'e', 'some(where (p.eft == allow))');
258258
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
259259

260-
final e = Enforcer.fromModelAndAdapter(m);
260+
final e = Enforcer.initWithModelAndAdapter(m);
261261

262262
e.addPermissionForUser('alice', ['data1', 'read']);
263263
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -282,7 +282,7 @@ void main() {
282282
m.addDef('e', 'e', 'some(where (p.eft == allow))');
283283
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
284284

285-
final e = Enforcer.fromModelAndAdapter(m);
285+
final e = Enforcer.initWithModelAndAdapter(m);
286286

287287
e.addPermissionForUser('alice', ['data1', 'read']);
288288
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -313,7 +313,7 @@ void main() {
313313
m.addDef('e', 'e', 'some(where (p.eft == allow))');
314314
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
315315

316-
final e = Enforcer.fromModelAndAdapter(m);
316+
final e = Enforcer.initWithModelAndAdapter(m);
317317

318318
e.addPermissionForUser('alice', ['data1', 'read']);
319319
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -345,7 +345,7 @@ void main() {
345345
m.addDef('e', 'e', 'some(where (p.eft == allow))');
346346
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
347347

348-
final e = Enforcer.fromModelAndAdapter(m);
348+
final e = Enforcer.initWithModelAndAdapter(m);
349349

350350
e.addPermissionForUser('alice', ['data1', 'read']);
351351
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -379,7 +379,7 @@ void main() {
379379
m.addDef('e', 'e', 'some(where (p.eft == allow))');
380380
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
381381

382-
final e = Enforcer.fromModelAndAdapter(m);
382+
final e = Enforcer.initWithModelAndAdapter(m);
383383

384384
e.addPermissionForUser('alice', ['data1', 'read']);
385385
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -415,7 +415,7 @@ void main() {
415415
m.addDef('e', 'e', 'some(where (p.eft == allow))');
416416
m.addDef('m', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
417417

418-
final e = Enforcer.fromModelAndAdapter(m);
418+
final e = Enforcer.initWithModelAndAdapter(m);
419419

420420
e.addPermissionForUser('alice', ['data1', 'read']);
421421
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -465,7 +465,7 @@ m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
465465
final model = Model();
466466
model.loadModelFromText(text);
467467

468-
final e = Enforcer.fromModelAndAdapter(model);
468+
final e = Enforcer.initWithModelAndAdapter(model);
469469

470470
e.addPermissionForUser('alice', ['data1', 'read']);
471471
e.addPermissionForUser('bob', ['data2', 'write']);
@@ -492,7 +492,7 @@ m = g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act
492492
model.addDef(
493493
'm', 'm', 'g(r.sub, p.sub) && r.obj == p.obj && r.act == p.act');
494494

495-
final e = Enforcer.fromModelAndAdapter(model);
495+
final e = Enforcer.initWithModelAndAdapter(model);
496496

497497
e.addPermissionForUser('alice', ['data1', 'read']);
498498
e.addPermissionForUser('bob', ['data2', 'write']);

test/logger/logger_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ void main() {
6767
'm.m: r_sub == p_sub && keyMatch(r_obj, p_obj) && regexMatch(r_act, p_act)');
6868
});
6969
group('test logPolicy', () {
70-
final enf = Enforcer.fromModelPathAndPolicyFile(
70+
final enf = Enforcer.initWithFile(
7171
'casbin_examples/basic_model.conf',
7272
'casbin_examples/basic_policy.csv',
7373
);
@@ -79,7 +79,7 @@ void main() {
7979
});
8080

8181
group('test logRole', () {
82-
final enf = Enforcer.fromModelPathAndPolicyFile(
82+
final enf = Enforcer.initWithFile(
8383
'casbin_examples/rbac_with_domains_model.conf',
8484
'casbin_examples/rbac_with_domains_policy.csv',
8585
);

test/model/model_test.dart

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ void main() {
3535
final rbacWithNotDenyModel = 'casbin_examples/rbac_with_not_deny_model.conf';
3636

3737
group('Test enforcing with basic model', () {
38-
final e =
39-
Enforcer.fromModelPathAndPolicyFile(basicModelPath, basicPolicyFile);
38+
final e = Enforcer.initWithFile(basicModelPath, basicPolicyFile);
4039

4140
testEnforce('test 1', e, 'alice', 'data1', 'read', true);
4241
testEnforce('test 2', e, 'alice', 'data1', 'write', false);

0 commit comments

Comments
 (0)