27
27
# ' @param allowed A list of allowed values
28
28
# ' @inheritParams entity
29
29
# ' @rdname enum
30
- enum = function (name , description = character (0 ), type = ' character' ,
30
+ enum = function (name , description = character (0 ), type = ' character' ,
31
31
value = character (0 ),max_length = 1 ,allowed ,... ) {
32
-
32
+
33
33
# new object
34
34
out = .enum(
35
- name = name ,
35
+ name = name ,
36
36
description = description ,
37
37
type = type ,
38
38
value = value ,
@@ -50,8 +50,8 @@ enum = function(name, description=character(0), type='character',
50
50
prototype = list (name = ' name not provided' ,
51
51
description = ' no description provided' ),
52
52
validity = function (object ) {
53
- check_list = object @ value %in% object @ allowed
54
-
53
+ check_list = (all( object @ value %in% object @ allowed ))
54
+
55
55
# check enum validity
56
56
msg = TRUE
57
57
if (! check_list ) {
@@ -70,7 +70,7 @@ enum = function(name, description=character(0), type='character',
70
70
setMethod(f = " value<-" ,
71
71
signature = c(" enum" ),
72
72
definition = function (obj ,value ) {
73
- if (value %in% obj @ allowed ) {
73
+ if (all( value %in% obj @ allowed ) ) {
74
74
obj @ value = value
75
75
} else {
76
76
stop(value ,' is not a valid choice for this enum.' )
@@ -84,7 +84,7 @@ setMethod(f = 'show',
84
84
signature = c(' enum' ),
85
85
definition = function (object ) {
86
86
callNextMethod()
87
-
87
+
88
88
cat(' allowed: ' ,paste0(object @ allowed ,collapse = ' , ' ))
89
89
cat(' \n ' )
90
90
}
0 commit comments