Coverage report for Casbin.Adapter.Memory.Policy.

Generated at 18/02/2019 12:10:19 by DelphiCodeCoverage - an open source tool for Delphi Code Coverage.

Statistics for Casbin.Adapter.Memory.Policy.pas

Number of lines covered23
Number of lines with code gen40
Line coverage57%


1
// Copyright 2018 by John Kouraklis and Contributors. All Rights Reserved.
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
unit Casbin.Adapter.Memory.Policy;
15
16
interface
17
18
uses
19
  Casbin.Adapter.Filesystem, Casbin.Adapter.Policy.Types,
20
  Casbin.Core.Base.Types, Casbin.Adapter.Base, System.Classes;
21
22
type
23
  TPolicyMemoryAdapter = class (TBaseAdapter, IPolicyAdapter)
24
  private
25
    procedure resetSections;
26
  protected
27
{$REGION 'IPolicyAdapter'}
28
    procedure add(const aTag: string);
29
    function getAutoSave: Boolean;
30
    function getCached: Boolean;
31
32
    procedure setAutoSave(const aValue: Boolean);
33
    procedure setCached(const aValue: Boolean);
34
35
    function getCacheSize: Integer;
36
    procedure setCacheSize(const aValue: Integer);
37
{$ENDREGION}
38
  public
39
{$REGION 'IAdapter'}
40
    constructor Create;
41
    procedure load(const aFilter: TFilterArray = []); override;
42
    procedure save; override;
43
{$ENDREGION}
44
{$REGION 'IPolicyAdapter'}
45
    procedure remove(const aPolicyDefinition: string); overload;
46
{$ENDREGION}
47
  end;
48
implementation
49
50
uses
51
  System.SysUtils;
52
53
procedure TPolicyMemoryAdapter.add(const aTag: string);
54
begin
55
  if getAssertions.IndexOf(aTag)=-1 then
56
    getAssertions.Add(aTag);
57
end;
58
59
constructor TPolicyMemoryAdapter.Create;
60
begin
61
  inherited;
62
  resetSections;
63
end;
64
65
function TPolicyMemoryAdapter.getAutoSave: Boolean;
66
begin
67
  Result:=True;
68
end;
69
70
function TPolicyMemoryAdapter.getCached: Boolean;
71
begin
72
  Result:=False;
73
end;
74
75
function TPolicyMemoryAdapter.getCacheSize: Integer;
76
begin
77
  Result:=0;
78
end;
79
80
procedure TPolicyMemoryAdapter.load(const aFilter: TFilterArray);
81
begin
82
  inherited;
83
  clear;
84
  resetSections;
85
end;
86
87
procedure TPolicyMemoryAdapter.remove(const aPolicyDefinition: string);
88
begin
89
  if getAssertions.IndexOf(aPolicyDefinition)>-1 then
90
    getAssertions.Delete(getAssertions.IndexOf(aPolicyDefinition));
91
end;
92
93
procedure TPolicyMemoryAdapter.resetSections;
94
begin
95
  if (getAssertions.Count=0) then
96
     getAssertions.Add('[default]')
97
  else
98
  if ((getAssertions.Count>=1) and
99
                    (uppercase(getAssertions.Items[0])<>'[DEFAULT]')) then
100
    getAssertions.Insert(0, '[default]');
101
end;
102
103
procedure TPolicyMemoryAdapter.save;
104
begin
105
  inherited;
106
107
end;
108
109
procedure TPolicyMemoryAdapter.setAutoSave(const aValue: Boolean);
110
begin
111
112
end;
113
114
procedure TPolicyMemoryAdapter.setCached(const aValue: Boolean);
115
begin
116
117
end;
118
119
procedure TPolicyMemoryAdapter.setCacheSize(const aValue: Integer);
120
begin
121
122
end;
123
124
end.