I'm building the REST API of a platform I'm working on in Ruby, on top of Sinatra.
Data comes in during a POST, at that stage, I check the format of parsed JSON against a validation hash built for each route with hash_validator.
The POST data, if valid, is passed into as a single hash to create a new class (e.g. User). So at the initialization, I check each variable to make sure they exist and are not nil.
Parts of the same object can reside in various collections (UserInfo, UserSubscriptions, UserPasswordHash etc.), so when loading the class from data store, I again validate each hash received through (in my case, Mongo).
This works so far but with a lot of repetitions of variable names around the code and it may still not be data-proof.
I'm following my engineering guts as much as possible on this but is there a common model to follow when validating input at various stages in the app?