diff --git a/src/FileTemplates.jl b/src/FileTemplates.jl index c096d79..26205bd 100644 --- a/src/FileTemplates.jl +++ b/src/FileTemplates.jl @@ -128,19 +128,19 @@ function newvalidator(validator_name::String; pluralize::Bool = true) :: String using SearchLight, SearchLight.Validation - function not_empty(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel} + function not_empty(field::Symbol, m::T)::ValidationResult where {T<:AbstractModel} isempty(getfield(m, field)) && return ValidationResult(invalid, :not_empty, "should not be empty") ValidationResult(valid) end - function is_int(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel} + function is_int(field::Symbol, m::T)::ValidationResult where {T<:AbstractModel} isa(getfield(m, field), Int) || return ValidationResult(invalid, :is_int, "should be an int") ValidationResult(valid) end - function is_unique(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel} + function is_unique(field::Symbol, m::T)::ValidationResult where {T<:AbstractModel} obj = findone(typeof(m); NamedTuple(field => getfield(m, field))... ) if ( obj !== nothing && ! ispersisted(m) ) return ValidationResult(invalid, :is_unique, "already exists") diff --git a/src/Validation.jl b/src/Validation.jl index dffced4..5c3561e 100644 --- a/src/Validation.jl +++ b/src/Validation.jl @@ -34,19 +34,19 @@ Creates Validation rule for a Model's field # Examples ```julia -julia> function not_empty(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel} +julia> function not_empty(field::Symbol, m::T)::ValidationResult where {T<:AbstractModel} isempty(getfield(m, field)) && return ValidationResult(invalid, :not_empty, "should not be empty") - + ValidationResult(valid) end -julia> function is_int(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel} +julia> function is_int(field::Symbol, m::T)::ValidationResult where {T<:AbstractModel} isa(getfield(m, field), Int) || return ValidationResult(invalid, :is_int, "should be an int") - + ValidationResult(valid) end -julia> function is_unique(field::Symbol, m::T, args::Vararg{Any})::ValidationResult where {T<:AbstractModel} +julia> function is_unique(field::Symbol, m::T)::ValidationResult where {T<:AbstractModel} obj = findone(typeof(m); NamedTuple(field => getfield(m, field))... ) if ( obj !== nothing && ! ispersisted(m) ) return ValidationResult(invalid, :is_unique, "already exists")