Rails-assets.org Could Become Rubygems.org's Best Friend
By: Americo Savinon

One of the beauties of the Ruby ecosystem is the vast number of gems that are available for us as developers, all we have to do is to gem install or add the gem we want to use in our Ruby on Rails app, run bundle install, and voilá, that gem is ready for use.  The magic doesn’t end there though, as there is a lot of work and logic happening behind the scenes every time we run those commands.  One of them is something called Dependency Management, and the idea it’s pretty simple: “If gem A depends on gem B and B depends on C, then when I request A, go fetch B and go fetch C”.

A common pattern that we see everyday while coding a Rails app, it’s looking for a library or gem and adding to our gem file. When we do that, we are pretty much signing a contract saying: “I’m going to use your features, I’m gonna trust and rely on you”.  Gem owners know this and most of time they keep their gems up to date (at least the most popular ones).  But what happens when the gem owner doesn’t update their gem when a new Rails version is released?  Or they get tired and bored of maintaining the gem?  In these cases, the contract is voided and we are left carrying the bag.  What if there is an amazing Javascript library that we want to use, but there isn’t a gem that wraps it?  For all these cases, there is new tool for the job.


Enter Rails-assets.org

Rails-assets.org is new solution to assets management in Rails.  The idea is to follow the steps of rubygems.org, but goes a step further (as described on their website): “It automatically coverts the packaged components into the gem that are easily droppable into your asset pipeline and stay up to date”.  This is how it works:

  • First you include: source 'https://rails-assets.org' in your gemfile
  • Then call the bower package you want to include in your project: gem 'rails-assets-BOWER_PACKAGE_NAME’
  • Inside you application.js and .css, require those .js and .css files needed based on your library install instructions
  • Run bundle install

After that, your library is installed as a gem and you are off to the races.  Behind the scenes, rails-assets.org will fetch the component from Bower’s registry, then analyze its bower.json file and repackage the component as a valid gem.  All dependencies are handled for you.  It’s a pretty clever way to use the latest version of a given library.

Rails-assets.org is a new project and still maturing.  Like anything, it has its pros and cons (like you can’t specify a given package version like we can using rubygems.org), but with time it could become one of our best tools in our Ruby belt.

SHARE:

Meet Americo:
Americo is a Software Engineer at WeddingWire. Americo is from Mexico City and has a Computer Science degree from Monterrey Institute of Technology. When he doesn't have his nose buried in RubyMine, Americo likes reading, running, cycling, playing poker, finances, riding his motorcycle, and long romantic dinners with his wife.