Monthly Archives: December 2010

Getting started with Ruby – TOC

Hi,

I have written a series of articles (in several parts) in an attempt to guide beginners to get comfortable with Ruby. This article is my attempt to build a TOC (Table of Contents) for it to act as an index for people to get a brief idea regarding what each article is about and help them get to the sections they are interested in.

  • Getting started with Ruby – Part 1 : In this article I begin with an introduction to myself and my motivation behind writing these articles. I give an introduction to Ruby, about how to get started with building your development environment and introduce a few tools that ship along with Ruby which will make your life that much better.
  • Getting started with Ruby – Part 2 : In this article I introduce Ruby in slightly more detail and I get started with describing different data types in Ruby. I cover Strings and Numbers in this article.
  • Getting started with Ruby – Part 3 : In this article I continue from my previous article describing data types in Ruby and cover Ranges and Arrays.
  • Getting started with Ruby – Part 4 : In this article I continue further and cover Hashes, one of the most commonly used data types in Ruby. I also introduce blocks and about using blocks with functions.
  • Getting started with Ruby – Part 5 : In this article I move onto describing various looping constructs in Ruby, and also various flow control modifiers in Ruby. After that I introduce Variables, Symbols, Constants, Methods and Global Variables in Ruby.
  • Getting started with Ruby – Part 6 : After having covered basics of various constructs in Ruby, I considered it better to take a problem statement and solve it in Ruby to bring most of what we’ve discussed into use. I chose Google Codejam 2009′s qualification round problem – Alien Language

I tried to be clear, precise and specific. My intention was write more code than to waste time in trying to explain and so I’ve used code comments to help people understand what each part of the code is meant to do. I have plans on going further and go onto describing classes & modules, sometime soon, even though I expected more people to read and give their feedback, but owing to a lot of work and hence a lack of time, I haven’t been able to do much justice to the same, but hopefully I will be able to do so very soon. I hope it helps people appreciate Ruby and motivate them to learn and understand it.

MongoMapper Plugin – Versionable

There was a requirement at one of our projects here at Artha42 Innovations Private Limited that our Mongo Mapper documents have inherent versioning so as to be able to track the changes being made and also if required revert the changes to a previous state. Since we’re using MongoMapper, I set out to create a simple plugin for the same to add the required functionality.

Initially, from the initial research I did, I found Shapado had an implementation of exactly what I wanted, however when I studied and understood their implementation in detail, I realized that it doesn’t really work that well in most scenarios, especially the ones we were tackling in our project. Shapado’s versionable allows you to define a set of keys for a document, whose changes would trigger creation of new versions. However in our project we needed to track changes at the complete document level, i.e. even for changes in the associations. Also the versions were embedded within the document itself, which implied that the document would grow in size very rapidly, even though our changes in each iteration could be minor, since each version would literally be a snapshot of the complete document itself.

So we made quite a few design changes in the same, externalized the versions, changed the way one would enable versioning since in our case we wouldn’t be keeping track of changes only in specific keys. Even here, we found that there were certain bottlenecks in the case if there were a whole lot of versions, for which we introduced the :limit feature which allows us to define how many of versions would need to be loaded instead of loading all of them at once.

The result of it was mm-versionable.

If you have any comments, suggestions, requests, queries or feedback, please do let us know in the comments section below.