This is a fresh look at an actual problem: how Updraft parses its incoming document creation requests. Presently this is tackled in a rather ad-hoc way, in that there are a number of underspecified hashes, we signal invalid data by raising exceptions, and we sometimes get validation errors in unexpected places.
The approach here is:
-
"Parse, don't validate" - everywhere that we check an input is well-specified, we also convert the external representation into the object we actually need
-
inspired by monads, but is possibly not actually compliant with the monad laws. (Yes, this is why we have the rather opaque method names
unitandlift)
The biggest ugliness in this right now is that the Result type might hold a hash or an array and you have to know which of them you've been handed in order to know how to use it, which seems kind of ungainly. Look in template.rb to see what I mean
Start by reading spec/stitchup/template_spec.rb to see how it hangs together
Some of these links are marked [SB] meaning they are (or, at least, should be ;-) accessible only to @simplybusiness folk