Not Quite Callbacks
I’ve been working on application architectures based on Uncle Bob’s Ruby Midwest talk, following the hexagonal architectural pattern. I posted an article a couple months ago showing a way that works fairly well in Rails, and some accompanying Rails example code. But there was one thing I wasn’t quite happy with. The problem is that we used callbacks (actually, a publish/subscribe mechanism) in a situation where they don’t seem to quite fit: def show interactor.on(:display) { |order| render order } interactor.on(:not_found) { |order_id| render status: 404 } interactor.get(params[:id]) end What we really want is to respond in different ways, depending on the result of the call to interactor.get(). There’s no good reason to define the responses before the call. It makes a lot more sense to define the responses after the call, because they’ll happen after the call. I’d much prefer that the code be written in the order that it will be run. ...