Add copyright notice, update has_values method
This commit is contained in:
parent
d608999990
commit
2413e125ce
1 changed files with 25 additions and 20 deletions
|
@ -1,3 +1,21 @@
|
||||||
|
# CORE FRAMEWORK SOURCE FILE
|
||||||
|
# Copyright (c) 2024 The StarOpenSource Project & Contributors
|
||||||
|
# Licensed under the GNU Affero General Public License v3
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU Affero General Public License as
|
||||||
|
# published by the Free Software Foundation, either version 3 of the
|
||||||
|
# License, or (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU Affero General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
## Validates some data against a set of rules.
|
||||||
extends Node
|
extends Node
|
||||||
class_name CoreValidationSingle
|
class_name CoreValidationSingle
|
||||||
|
|
||||||
|
@ -112,26 +130,13 @@ func evaluate() -> bool:
|
||||||
# Perform check
|
# Perform check
|
||||||
if data > rule["maximum"]: failures.append(core.stringify_variables("Data is smaller than minimum %type% value %expected%", { "type": rule["matched_against"], "expected": rule["maximum"] }))
|
if data > rule["maximum"]: failures.append(core.stringify_variables("Data is smaller than minimum %type% value %expected%", { "type": rule["matched_against"], "expected": rule["maximum"] }))
|
||||||
CoreTypes.ValidationType.HAS_VALUES:
|
CoreTypes.ValidationType.HAS_VALUES:
|
||||||
# Used later
|
|
||||||
var success: bool = false
|
var success: bool = false
|
||||||
|
|
||||||
if rule["all_required"]:
|
for value in rule["values"]:
|
||||||
# Invert usage
|
if data == value:
|
||||||
success = true
|
success = true
|
||||||
|
|
||||||
for value in rule["values"]:
|
if !success: failures.append("Data did not match a single provided value")
|
||||||
if data != value:
|
|
||||||
# One value did not match
|
|
||||||
success = false
|
|
||||||
|
|
||||||
if !success: failures.append("Data did not match all provided values")
|
|
||||||
else:
|
|
||||||
for value in rule["values"]:
|
|
||||||
if data == value:
|
|
||||||
# One value did match
|
|
||||||
success = true
|
|
||||||
|
|
||||||
if !success: failures.append("Data did not match a single provided value")
|
|
||||||
CoreTypes.ValidationType.CONTAINS:
|
CoreTypes.ValidationType.CONTAINS:
|
||||||
# If not a String or StringName, skip
|
# If not a String or StringName, skip
|
||||||
if typeof(data) != Variant.Type.TYPE_STRING or typeof(data) != Variant.Type.TYPE_STRING_NAME:
|
if typeof(data) != Variant.Type.TYPE_STRING or typeof(data) != Variant.Type.TYPE_STRING_NAME:
|
||||||
|
@ -250,8 +255,8 @@ func has_maximum_value_float(maximum: float) -> CoreValidationSingle:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
# +++ values +++
|
# +++ values +++
|
||||||
func has_values(values: Array, all_required: bool) -> CoreValidationSingle:
|
func has_values(values: Array) -> CoreValidationSingle:
|
||||||
rules.append({ "type": CoreTypes.ValidationType.HAS_VALUES, "values": values, "all_required": all_required })
|
rules.append({ "type": CoreTypes.ValidationType.HAS_VALUES, "values": values })
|
||||||
return self
|
return self
|
||||||
|
|
||||||
func contains(values: Array[String], minimum_matches: int = 1) -> CoreValidationSingle:
|
func contains(values: Array[String], minimum_matches: int = 1) -> CoreValidationSingle:
|
||||||
|
|
Loading…
Reference in a new issue