better enum status validation (#13486)

This commit is contained in:
William Cheng
2022-09-22 10:04:03 +08:00
committed by GitHub
parent 5f9910dcab
commit e146afbea1
11 changed files with 113 additions and 0 deletions

View File

@@ -34,6 +34,9 @@ Zebra <- R6::R6Class(
self$`className` <- `className`
}
if (!is.null(`type`)) {
if (!(`type` %in% c("plains", "mountain", "grevys"))) {
stop(paste("Error! \"", `type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
}
stopifnot(is.character(`type`), length(`type`) == 1)
self$`type` <- `type`
}
@@ -68,6 +71,9 @@ Zebra <- R6::R6Class(
fromJSON = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`type`)) {
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
}
self$`type` <- this_object$`type`
}
if (!is.null(this_object$`className`)) {
@@ -114,6 +120,9 @@ Zebra <- R6::R6Class(
#' @export
fromJSONString = function(input_json) {
this_object <- jsonlite::fromJSON(input_json)
if (!is.null(this_object$`type`) && !(this_object$`type` %in% c("plains", "mountain", "grevys"))) {
stop(paste("Error! \"", this_object$`type`, "\" cannot be assigned to `type`. Must be \"plains\", \"mountain\", \"grevys\".", sep = ""))
}
self$`type` <- this_object$`type`
self$`className` <- this_object$`className`
self