You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
910 B
Lua
37 lines
910 B
Lua
return function(key, rule, mandatory)
|
|
if mandatory == nil then
|
|
mandatory = true
|
|
end
|
|
|
|
return {
|
|
messages = {
|
|
affirmative = {
|
|
standard = "{{key}} must be defined"
|
|
},
|
|
negative = {
|
|
standard = "{{key}} must not be defined"
|
|
}
|
|
},
|
|
apply = function(context)
|
|
context.key = key
|
|
|
|
if context.input[key] == nil then
|
|
context.result = (mandatory == false)
|
|
return
|
|
end
|
|
|
|
if not rule then
|
|
context.result = true
|
|
return
|
|
end
|
|
|
|
local child_context = context:new_child(rule)
|
|
child_context.name = key
|
|
child_context.input = context.input[key]
|
|
child_context:apply_rule()
|
|
|
|
context.result = child_context.result
|
|
end
|
|
}
|
|
end
|