Posts for Tag: gems

Choosing a Ruby gem

Instead of writing yet another list of gems you should be using, i'll try to explain how i choose a gem for a particular task or function. This is by no means a complete checklist, it's just my typical way of going about things.

Rubygems

If you're a Ruby developer you are probably familiar with the website rubygems.org. It's "the" repository for all information about Ruby gems.

Things i find important when looking for a gem:

Number of total downloads

Though it will not tell you whether a gem is any good, it does tell you whether a lot of people looked at it as a good candidate for the job you need done. It's also an indicator for the community you can expect around this gem (helps when looking for tutorials, documentation, and general help).

Release date of the last versions

This will show you how frequently is the gem updated, which is useful to know how fast are fixes and new features introduced.

Sometimes it can happen that a really good gem hasn't had a release in a while. For example a couple of weeks ago i was looking for a gem that wrapped the Marvel Comics API. If you look for gems for that you find that most are really old. Doesn't mean they don't work properly, it just means that the API hasn't changed since and they are still relevant. When that's the case, i usually go for the one that was released last, just because the author had the gift of hindsight over the other ones and might have done a better, more polished job at it. Not always true, but... :)

Dependencies and License

To a lesser degree, i also take a look at these.

The less dependencies a gem has the lighter your code will be. Again, not always true, but it's a good rule of thumb. Also pay attention if the license is compatible with your own project.

    If a particular gem feels like a good candidate, I then visit its...

    ...Github/Repository/Website

    There, i usually check for a couple of things:

    Documentation

    This is how you learn how to use the gem, so it helps if the docs are really good (and maintained!).

    If it's an opensource project (which most gems are), then i also look for:

    Last commit date

    A clear indicator of the health of the gem. Also, take into consideration what i wrote earlier about gems that don't update often: it might be because they just don't need to.

    Number of contributors, commenters, discussions

    They show how active the community is around this gem. If big, it helps later when trying to find information how to do things if you get stuck, for example.

    Number of open issues (and resolved)

    If you take a glance at the last issues, when they were created, when they were replied to or resolved, this will also give you a good idea of how active the developers are, and how fast can you expect a response if you report something.

    Code

    Looking at the source code, though not as important as the rest, can also provide some insight to how performant, optimized the gem is at the job it does. It might also help you figure out if will be easy to monkey patch something to fit your needs later. And who knows, you mighty also learn something new from it :)

    Conclusion

    Though not (by any means) a complete guide for choosing a gem, this might be a good starting point. Also, some of these "metrics" might apply for choosing other software and code libraries.

    Like most things in life, your mileage may vary.

    Happy coding!

    A collection of useful Ruby/Rails gems

    Since lately i've been working a lot with Ruby (Android and Java as well, but that's a different story), i figured i posted a couple of interesting gems that will make your life easier, especially but not only for rails.

    Slim

    Slim is a templating engine (like ERB or HAML) which pursues simplicity. It helps you write an insane amount less HTML and Rails code. You will not believe your eyes. An example:

    In HTML

    <body> <h1>Markup examples</h1> <div id="content"> <p>This example shows you how a basic Slim file looks like.</p> <%= yield %> </div> </body>

    The same in Slim

    body   h1 Markup examples   #content     p This example shows you how a basic Slim file looks like.     == yield

    Now tell me which one you prefer to write ;)

    Stamp

    A fantastic tool to format dates based on human readable formats. Why use Date.today.strftime("%Y/%m/%d") when you can use Date.today.stamp("2012/12/13")? Sweet, right?

    Bugsnag

    Bugsnag is web site exception grabbing on steroids. It basically monitors your website alerting you of any exceptions and providing the relevant information needed so you don't have to debug your production server.

    Cool thing is, there are "bindings" for multiple languages and frameworks. You can find the one for Ruby/Rails here. 

    Honey Badger

    Honey badger has a really simple purpose: To make sure you know which server you are in (say, testing, dev, production) by displaying a small "badge" with the name of your choosing.

    If you are like me you can easily think you are debugging something in testing when you are really looking at production. Ok, maybe that's just me, but the badge does look cool, right? :)

    God

    Now, i'm not one to call the name of the Lord in vain (i am!), but God is something i can no longer do without. It's a process monitoring framework written in ruby that keeps an eye on your server's, say nginx, apache or mysql and makes sure they are always up.

    Further checks can be done, like for example restart the server when memory usage goes above X or CPU usage goes above Y. It is also capable of notifying you by email, jabber, twitter, you name it, when things happen. It's a true life saver :)

    Hope you find these gems useful, as i did, and if you have some that i might find interesting, please do share via twitter :)