We allow users to submit a file to allow batch upload so they won’t have to enter each item through a GUI interface. Currently, we have a very simple validation scheme: read the key value pairs, check against a white list, check that users are valid, inject the contents.
I would like to script the validation using Ruby and would like to be able to add validation rules in the future.
How do I design this?
Make an array of rules. You can store the rules as lambdas, or store their function names as symbols, or strings. whatever is easiest.
Then check each pair against the rule set. For lambdas it would be something like:
If you store symbols use
send(rule,pair). For strings,eval "#{rule}(pair)"