SuperModel – to sexy up your Ruby models

A few months ago, my friend Chu Yeow and I released a Ruby gem called ActiveCouch which was designed to be a very elegant Ruby wrapper for the exciting new phenomenon – CouchDB. ActiveCouch was my first shot at a Ruby library and I had a lot of fun creating elegant DSL’s (a lot of which were inspired from ActiveRecord and ActiveResource). In essence, ActiveCouch lets you define models like so:

While this is great, I found myself using these semantics more often in other Ruby libraries that I started to work on. Thus was born – SuperModel.

SuperModel’s aim is to wrap semantics such as has, has_one, has_many (which are familiar to many Ruby/Rails developers) in a re-usable library which can form the basis for other such libraries. For instance, I am currently in the process of re-writing ActiveCouch so that ActiveCouch::Base inherits from SuperModel::Base. By doing so, all the ‘modeling’ semantics will be taken care of by SuperModel and ActiveCouch can deal with interfacing with CouchDB.

SuperModel also gives you serialization for free (currently only JSON, but future releases will also include XML, YAML, etc.) So, methods such as to_json, to_xml and to_yaml will let you serialize/de-serialize SuperModel objects in/from any format that you want.

About

I’m Arun Thampi, a Ruby developer at Wego, the kickass travel meta-search engine based in Singapore. We’re great believers in the power of open source, and this is my personal chronicle of stuff that I either work on or am impressed and excited by.

My open source projects are hosted by the great guys at GitHub, and my personal blog is here.

P.S. I’m also a big fan of Seth Rogen and his movies (that would explain the address of this blog)