Coverage report for Casbin.Adapter.Base.

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

Statistics for Casbin.Adapter.Base.pas

Number of lines covered34
Number of lines with code gen43
Line coverage79%


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.Base;
15
16
interface
17
18
uses
19
  Casbin.Core.Base.Types, Casbin.Adapter.Types, Casbin.Core.Logger.Types,
20
  System.Generics.Collections;
21
22
type
23
  {$REGION 'This is the base class for all Adapters'}
24
  /// <summary>
25
  ///   This is the base class for all Adapters
26
  /// </summary>
27
  /// <remarks>
28
  ///   <para>
29
  ///     Subclass this if you want to create a generic adapter.
30
  ///   </para>
31
  /// </remarks>
32
  {$ENDREGION}
33
  TBaseAdapter = class (TBaseInterfacedObject, IAdapter)
34
  private
35
    fLogger: ILogger;
36
    fAssertions: TList<string>;
37
  protected
38
    fFiltered: Boolean;   //PALOFF
39
    fFilter: TFilterArray;  //PALOFF
40
  protected
41
{$REGION 'Interface'}
42
    function getAssertions: TList<string>;
43
    function getLogger: ILogger; virtual;  //PALOFF
44
    function getFilter: TFilterArray;
45
    procedure load(const aFilter: TFilterArray); virtual;
46
    procedure save; virtual; abstract;
47
    procedure setAssertions(const aValue: TList<string>); virtual;
48
    procedure setLogger(const aValue: ILogger);
49
    function toOutputString: string; virtual;   //PALOFF
50
    procedure clear;
51
    function getFiltered: boolean;
52
{$ENDREGION}
53
  public
54
    constructor Create;
55
    destructor Destroy; override;
56
  end;
57
58
implementation
59
60
uses
61
  Casbin.Core.Logger.Default;
62
63
procedure TBaseAdapter.clear;
64
begin
65
  fAssertions.Clear;
66
end;
67
68
constructor TBaseAdapter.Create;
69
begin
70
  inherited;
71
  fAssertions:=TList<string>.Create;
72
  fLogger:=TDefaultLogger.Create;
73
  fFiltered:=False;
74
end;
75
76
destructor TBaseAdapter.Destroy;
77
begin
78
  fAssertions.Free;
79
  inherited;
80
end;
81
82
function TBaseAdapter.getAssertions: TList<string>;
83
begin
84
  Result:=fAssertions;
85
end;
86
87
function TBaseAdapter.getFilter: TFilterArray;
88
begin
89
  Result:=fFilter;
90
end;
91
92
function TBaseAdapter.getFiltered: boolean;
93
begin
94
  Result:=fFiltered;
95
end;
96
97
function TBaseAdapter.getLogger: ILogger;
98
begin
99
  Result:=fLogger;
100
end;
101
102
procedure TBaseAdapter.load(const aFilter: TFilterArray);
103
begin
104
  fFiltered:= Length(aFilter) <> 0;
105
  fFilter:=aFilter;
106
end;
107
108
procedure TBaseAdapter.setAssertions(const aValue: TList<string>);
109
begin
110
  fAssertions:=aValue;
111
end;
112
113
procedure TBaseAdapter.setLogger(const aValue: ILogger);
114
begin
115
  fLogger:=nil;
116
  if Assigned(aValue) then
117
    fLogger:=aValue
118
  else
119
    fLogger:=TDefaultLogger.Create;
120
end;
121
122
function TBaseAdapter.toOutputString: string;
123
var
124
  item: string;
125
begin
126
  result:='';
127
  for item in fAssertions do
128
    Result:=Result+item+sLineBreak;
129
end;
130
131
end.