A skeleton as warden
That was a bumpy ride. Yesterday I decided to work on the next part of a small project: do a basic web app to allow users to register, and use a mainly jQueryesque app to do some task managing.
I’ve been using Rails for some years now, still a beginner, but I also did give Padrino and Sinatra some spins just to get a feeling. Lately I’ve been anxious to try out Sinatra a bit more to do [blazing fast awesome] apps so I thought that Sinatra was probably a good choice to use in this new case. In the same way I chose Authlogic to do all the authentication, and … DataMapper as the ORM.
Experimented readers are already laughing or smiling after that last sentence because Authlogic and DataMapper are not friends. I looked around and tested various bits and stuff, even changed some code, but in the end, someone on the freenode #datamapper channel reminded me of a little guy : Warden. Oh boy, it’s incredible how much patience those guys had last night with me. I kept stumbling on the same mistakes not understanding some basic stuff. I could understand the idea behind the code, but didn’t know exactly how all was fitting.
Two gists were particularly interesting and complete : Sinatra warden example and Warden and Sinatra. The first one is quite complete and easy to understand, the last one shows that the first file of the first gist goes into the main app class. That was one of the part I missed for hours.
After that I had trouble to get a proper authenticate strategy going on in my model because of some complexity in the first gist one of the datamapper people shared with me. After some fiddling around and more questions another guy gisted another class, simpler. He even added some comments to it.
Then this morning I thought a bit more about my app and decided it needed a bit of structure, so I checked around and found a post on stack overflow : Using Sinatra for larger projects via multiple files that came with a github repository. This repository (as the stack overflow post says) is a monk skeleton. Basicly Monk allows you to kick start a Sinatra app (I suppose you could use it with frameworks) by cloning a remote git repository content as skeleton, or template for your app. Since that skeleton was Sequel based I forked it, made necessary change to use DataMapper, added a Gemfile, the last night warden based auth stuff and a thor based script to replace a rake task and voila.
So … what a night, what a morning. I wonder if I unlocked any achievements with this. Morning green tea at least, and some warm feeling about having learn something new. So : namelessjon, draginx, dkubb, Phrogz, wycats (for Thor) : thank you for your work, patience and help !


