Skip to content

Commit

Permalink
Ajustes de códigos
Browse files Browse the repository at this point in the history
  • Loading branch information
dliocode committed Feb 22, 2022
1 parent f451a0c commit 0d56664
Show file tree
Hide file tree
Showing 21 changed files with 54 additions and 52 deletions.
2 changes: 1 addition & 1 deletion src/core/DataValidator.Context.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
interface

uses
DataValidator.Types, DataValidator.ItemBase.Intf, DataValidator.Information.Intf,
DataValidator.Types, DataValidator.ItemBase.Intf,
System.Generics.Collections, System.Rtti;

type
Expand Down
11 changes: 4 additions & 7 deletions src/core/DataValidator.Context.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface

uses
DataValidator.Types,
DataValidator.Context.Intf, DataValidator.ItemBase.Intf, DataValidator.Information.Intf,
DataValidator.Context.Intf, DataValidator.ItemBase.Intf,
System.RTTI, System.JSON, System.Generics.Collections, System.SysUtils, System.Variants;

type
Expand Down Expand Up @@ -298,18 +298,15 @@ constructor TDataValidatorContext<T>.Create(const AOwner: T; const AValue: TJSON
procedure TDataValidatorContext<T>.AfterConstruction;
begin
inherited;

FList := TList<IDataValidatorItem>.Create;
FMessage := Default(TDataValidatorMessage);
FMessage := Default (TDataValidatorMessage);
FExecute := nil;
FIsNot := False;
end;

destructor TDataValidatorContext<T>.Destroy;
begin
FList.Free;

inherited;
end;

// Schema
Expand All @@ -322,7 +319,7 @@ function TDataValidatorContext<T>.AddSchema(const ASchema: IDataValidatorSchemaC
Result := FOwner;

if not Assigned(ASchema) then
raise Exception.Create('Schema is nil!');
raise EDataValidatorException.Create('Schema is nil!');

LListValidatorItem := (ASchema as IDataValidatorContextBase<IDataValidatorItem>).GetItem;

Expand Down Expand Up @@ -952,7 +949,7 @@ function TDataValidatorContext<T>.WithMessage(const AMessage: TDataValidatorWith
begin
Result := FOwner;

LDataValidatorMessage := Default(TDataValidatorMessage);
LDataValidatorMessage := Default (TDataValidatorMessage);

if Assigned(AMessage) then
AMessage(LDataValidatorMessage);
Expand Down
3 changes: 1 addition & 2 deletions src/core/DataValidator.Information.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
interface

uses
DataValidator.Types,
System.SysUtils;
DataValidator.Types;

type
IDataValidatorInformation = interface
Expand Down
5 changes: 1 addition & 4 deletions src/core/DataValidator.Information.pas
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,12 @@ implementation

constructor TDataValidatorInformations.Create;
begin
inherited;
FList := TList<IDataValidatorInformation>.Create;
end;

destructor TDataValidatorInformations.Destroy;
begin
FList.Free;

inherited;
end;

function TDataValidatorInformations.Add(const ADataInformation: IDataValidatorInformation): IDataValidatorInformations;
Expand Down Expand Up @@ -140,7 +137,7 @@ constructor TDataValidatorInformation.Create(const AValue: string; const AMessag

destructor TDataValidatorInformation.Destroy;
begin
inherited;

end;

function TDataValidatorInformation.Value: string;
Expand Down
6 changes: 3 additions & 3 deletions src/core/DataValidator.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface

IDataValidatorValueBase = interface(IDataValidatorValueBaseContext)
['{6FAD251E-6E4E-4359-B81D-EC08A0684489}']
function &End(): IDataValidatorValueResult;
function &End: IDataValidatorValueResult;
end;

IDataValidatorValueResult = interface(IDataValidatorValue)
Expand All @@ -86,13 +86,13 @@ interface

IDataValidatorJSON = interface
['{8409957E-995E-40F6-99F4-6867EEEA2E78}']
function Validate(const AName: string): IDataValidatorJSONBaseContext; overload;
function Validate(const AName: TArray<string>): IDataValidatorJSONBaseContext; overload;
function Validate(const AName: string): IDataValidatorJSONBaseContext; overload;
end;

IDataValidatorJSONBase = interface(IDataValidatorJSONBaseContext)
['{0AE8315D-D7BF-48CF-8917-DB1AE2A0881B}']
function &End(): IDataValidatorJSONResult;
function &End: IDataValidatorJSONResult;
end;

IDataValidatorJSONResult = interface(IDataValidatorJSON)
Expand Down
2 changes: 1 addition & 1 deletion src/core/DataValidator.ItemBase.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
interface

uses
DataValidator.Types, DataValidator.Result.Intf, DataValidator.Information.Intf,
DataValidator.Types, DataValidator.Result.Intf,
System.RTTI;

type
Expand Down
14 changes: 12 additions & 2 deletions src/core/DataValidator.ItemBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface

uses
DataValidator.Types,
DataValidator.ItemBase.Intf, DataValidator.Result.Intf, DataValidator.Information.Intf,
DataValidator.ItemBase.Intf, DataValidator.Result.Intf,
DataValidator.Result, DataValidator.Information,
System.SysUtils, System.RTTI, System.JSON, System.StrUtils, System.TypInfo;

Expand Down Expand Up @@ -125,7 +125,17 @@ procedure TDataValidatorItemBase.SetMessage(const AMessage: string);

procedure TDataValidatorItemBase.SetMessage(const AMessage: TDataValidatorMessage);
begin
FMessage := AMessage;
if not AMessage.Title.Trim.IsEmpty then
FMessage.Title := AMessage.Title;

if not AMessage.Message.Trim.IsEmpty then
FMessage.Message := AMessage.Message;

if not AMessage.Detail.Trim.IsEmpty then
FMessage.Detail := AMessage.Detail;

if not AMessage.Status.Trim.IsEmpty then
FMessage.Status := AMessage.Status;
end;

procedure TDataValidatorItemBase.SetExecute(const AExecute: TDataValidatorInformationExecute);
Expand Down
4 changes: 2 additions & 2 deletions src/core/DataValidator.JSON.Base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ TDataValidatorJSONBase = class(TDataValidatorJSONContext<IDataValidatorJSONBas
[weak]
FResult: IDataValidatorJSONResult;
public
function &End(): IDataValidatorJSONResult;
function &End: IDataValidatorJSONResult;

constructor Create(const AResult: IDataValidatorJSONResult; const AValue: TJSONPair); reintroduce;
destructor Destroy; override;
Expand All @@ -65,7 +65,7 @@ destructor TDataValidatorJSONBase.Destroy;
inherited Destroy;
end;

function TDataValidatorJSONBase.&End(): IDataValidatorJSONResult;
function TDataValidatorJSONBase.&End: IDataValidatorJSONResult;
begin
Result := FResult;
end;
Expand Down
4 changes: 2 additions & 2 deletions src/core/DataValidator.JSON.Context.Intf.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ interface

IDataValidatorJSONContextKey<T> = interface(IDataValidatorJSONContextKeyContext<T>)
['{54906AC4-363A-4031-927C-2D007C6279AC}']
function &End(): T;
function &End: T;
function IsOptional(): IDataValidatorJSONContextKey<T>; overload;
function IsOptional(const AExecute: TDataValidatorCustomResult): IDataValidatorJSONContextKey<T>; overload;
function IsRequired(): IDataValidatorJSONContextKey<T>; overload;
Expand All @@ -66,7 +66,7 @@ interface

IDataValidatorJSONContextValue<T> = interface(IDataValidatorJSONContextValueContext<T>)
['{320BD31E-810F-4EB6-A8C4-C17CA2C186DB}']
function &End(): T;
function &End: T;
function CustomJSONValue(const AExecute: TDataValidatorCustomJSONValue): IDataValidatorJSONContextValue<T>; overload;
function CustomJSONValue(const AExecute: TDataValidatorCustomJSONValueMessage): IDataValidatorJSONContextValue<T>; overload;
function CustomJSONValue(const AExecute: TDataValidatorCustomJSONMessage): IDataValidatorJSONContextValue<T>; overload;
Expand Down
6 changes: 3 additions & 3 deletions src/core/DataValidator.JSON.Context.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
interface

uses
DataValidator.JSON.Context.Intf, DataValidator.ItemBase.Intf, DataValidator.Information.Intf,
DataValidator.JSON.Context.Intf, DataValidator.ItemBase.Intf,
DataValidator.Types, DataValidator.Context,
System.JSON, System.Generics.Collections, System.SysUtils;

Expand Down Expand Up @@ -67,7 +67,7 @@ TDataValidatorJSONContext<T: IInterface> = class(TDataValidatorContext<IDataVa
function MinItems(const AMinItems: Integer): IDataValidatorJSONContextValue<T>;
function MaxItems(const AMaxItems: Integer): IDataValidatorJSONContextValue<T>;

function &End(): T;
function &End: T;

constructor Create(const AOwner: T; const AValue: TJSONPair);
destructor Destroy; override;
Expand All @@ -94,7 +94,7 @@ constructor TDataValidatorJSONContext<T>.Create(const AOwner: T; const AValue: T

destructor TDataValidatorJSONContext<T>.Destroy;
begin
inherited;
inherited Destroy;
end;

function TDataValidatorJSONContext<T>.Key: IDataValidatorJSONContextKey<T>;
Expand Down
21 changes: 10 additions & 11 deletions src/core/DataValidator.JSON.pas
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ TDataValidatorJSON = class(TInterfacedObject, IDataValidatorJSON, IDataValidat
function TValueToString(const AValue: TValue): string;
function TryGetValue(const AName: string; var AValue: IDataValidatorJSONBaseContext): Boolean;
public
function Validate(const AName: string): IDataValidatorJSONBaseContext; overload;
function Validate(const AName: TArray<string>): IDataValidatorJSONBaseContext; overload;
function Validate(const AName: string): IDataValidatorJSONBaseContext; overload;

function Check(): IDataValidatorResult;
function CheckAll(): IDataValidatorResult;
Expand All @@ -69,6 +69,7 @@ TDataValidatorJSON = class(TInterfacedObject, IDataValidatorJSON, IDataValidat
implementation

uses
DataValidator.Types,
DataValidator.Information.Intf, DataValidator.ItemBase.Intf, DataValidator.Context.Intf,
DataValidator.JSON.Base, DataValidator.Information, DataValidator.ItemBase.Sanitizer, DataValidator.ItemBase,
Validator.JSON.Key.IsRequired, Validator.JSON.Key.IsOptional, Validator.IsOptional;
Expand All @@ -78,7 +79,7 @@ implementation
constructor TDataValidatorJSON.Create(const AJSON: TJSONObject);
begin
if not Assigned(AJSON) then
raise Exception.Create('JSON is nil');
raise EDataValidatorException.Create('JSON is nil');

FJSON := AJSON;
FList := TList < TPair < string, IDataValidatorJSONBaseContext >>.Create();
Expand All @@ -87,7 +88,7 @@ constructor TDataValidatorJSON.Create(const AJSON: TJSONObject);
constructor TDataValidatorJSON.Create(const AJSON: TJSONArray);
begin
if not Assigned(AJSON) then
raise Exception.Create('JSON is nil');
raise EDataValidatorException.Create('JSON is nil');

FJSON := AJSON;
FList := TList < TPair < string, IDataValidatorJSONBaseContext >>.Create();
Expand All @@ -96,13 +97,6 @@ constructor TDataValidatorJSON.Create(const AJSON: TJSONArray);
destructor TDataValidatorJSON.Destroy;
begin
FList.Free;

inherited;
end;

function TDataValidatorJSON.Validate(const AName: string): IDataValidatorJSONBaseContext;
begin
Result := Validate([AName]);
end;

function TDataValidatorJSON.Validate(const AName: TArray<string>): IDataValidatorJSONBaseContext;
Expand All @@ -112,12 +106,17 @@ function TDataValidatorJSON.Validate(const AName: TArray<string>): IDataValidato
begin
LBase := TDataValidatorJSONBase.Create(Self, nil);

for I := 0 to Pred(Length(AName)) do
for I := Low(AName) to High(AName) do
FList.Add(TPair<string, IDataValidatorJSONBaseContext>.Create(AName[I], LBase));

Result := LBase;
end;

function TDataValidatorJSON.Validate(const AName: string): IDataValidatorJSONBaseContext;
begin
Result := Validate([AName]);
end;

function TDataValidatorJSON.Check: IDataValidatorResult;
begin
if FJSON is TJSONObject then
Expand Down
3 changes: 1 addition & 2 deletions src/core/DataValidator.Result.pas
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ constructor TDataValidatorResult.Create(const AOK: Boolean; const ADataInformati

destructor TDataValidatorResult.Destroy;
begin
FDataInformations := nil;
inherited;

end;

function TDataValidatorResult.OK: Boolean;
Expand Down
2 changes: 1 addition & 1 deletion src/core/DataValidator.Schema.Base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ TDataValidatorSchemaBase = class(TDataValidatorContext<IDataValidatorSchemaBas
[weak]
FDataValidatorSchema: IDataValidatorSchema;
public
function &End(): IDataValidatorSchemaContext;
function &End: IDataValidatorSchemaContext;

constructor Create(const ADataValidatorSchema: IDataValidatorSchema); reintroduce;
destructor Destroy; override;
Expand Down
3 changes: 2 additions & 1 deletion src/core/DataValidator.Schema.pas
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,12 @@ implementation

constructor TDataValidatorSchema.Create;
begin

end;

destructor TDataValidatorSchema.Destroy;
begin
inherited;

end;

function TDataValidatorSchema.Validate: IDataValidatorSchemaBaseContext;
Expand Down
5 changes: 4 additions & 1 deletion src/core/DataValidator.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
interface

uses
System.JSON;
System.JSON, System.SysUtils;

type
TDataValidatorMessage = record
Expand All @@ -61,6 +61,9 @@ TDataValidatorMessage = record
TDataValidatorInformationExecute = reference to procedure;
TDataValidatorWithMessage = reference to procedure(var AMessage: TDataValidatorMessage);

EDataValidatorException = class(Exception)
end;

implementation

end.
7 changes: 3 additions & 4 deletions src/core/DataValidator.Value.Base.pas
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ TDataValidatorValueBase = class(TDataValidatorContext<IDataValidatorValueBase>
FResult: IDataValidatorValueResult;
FValue: TArray<string>;
public
function &End(): IDataValidatorValueResult;

function &End: IDataValidatorValueResult;
function GetValues: TArray<string>;

constructor Create(const AResult: IDataValidatorValueResult; const AValue: TArray<string>); reintroduce;
Expand All @@ -59,16 +58,16 @@ implementation
constructor TDataValidatorValueBase.Create(const AResult: IDataValidatorValueResult; const AValue: TArray<string>);
begin
inherited Create(Self, '');
FValue := AValue;
FResult := AResult;
FValue := AValue;
end;

destructor TDataValidatorValueBase.Destroy;
begin
inherited Destroy;
end;

function TDataValidatorValueBase.&End(): IDataValidatorValueResult;
function TDataValidatorValueBase.&End: IDataValidatorValueResult;
begin
Result := FResult;
end;
Expand Down
2 changes: 0 additions & 2 deletions src/core/DataValidator.Value.pas
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ constructor TDataValidatorValue.Create;
destructor TDataValidatorValue.Destroy;
begin
FList.Free;

inherited;
end;

function TDataValidatorValue.Validate(const AValue: string): IDataValidatorValueBaseContext;
Expand Down
1 change: 0 additions & 1 deletion src/core/DataValidator.pas
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ interface
IDataValidatorSchemaContext = DataValidator.Context.Intf.IDataValidatorSchemaContext;

TDataValidator = class
private
public
class function Schema: IDataValidatorSchema;
class function Values: IDataValidatorValue;
Expand Down
1 change: 1 addition & 0 deletions src/sanitializators/Sanitizer.Base64.Decode.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ implementation

constructor TSanitizerBase64Decode.Create;
begin

end;

function TSanitizerBase64Decode.Sanitize: TValue;
Expand Down
1 change: 1 addition & 0 deletions src/sanitializators/Sanitizer.Trim.pas
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ implementation

constructor TSanitizerTrim.Create;
begin

end;

function TSanitizerTrim.Sanitize: TValue;
Expand Down
Loading

0 comments on commit 0d56664

Please sign in to comment.