Not only must the spice flow... but the flow must also spice!

September 28, 2009

Announcing the update_attribute gem on github!

This is just an announcement of my new (and first ever) plugin/gem! It's a humble little gem (of a gem) called update_attribute and here is its description:

Rails gem for simplifying calls to update_attribute on Active Record objects by allowing you to replace "attribute" (in update_attribute) with the actual name of the attribute to be updated and then just pass in the value to update that attribute to. The passed in value may be a string or a symbol (symbols will be converted to a string for you).


Usage and Examples:

Wihtout update_attribute:

    <active_record_object>.update_attribute(<attribute>, <value>)

With update_attribute:

    <active_record_object>.update_<attribute>(<value>)

Examples:

  user = User.find_by_username("Paul")
    # => #<User id: 1, username: "Paul", email: "atreides@muaddib.com", ...>
  user.update_username "Muad'Dib" # => true
  user.reload.username # => "Muad'Dib"

  user.update_username :Atreides # => true
  user.reload.username # => "Atreides"

  user.email # => "atreides@muaddib.com"
  user.update_email "paul@atreides.com" # => true
  user.reload.email # => "paul@atreides.com"

I plan to use this as a simple development environment booster as it's mainly just a keystroke saver. By development environment booster I just mean that it will be required (included) by my personal (non source-controlled) config/environments/development.rb file and will just be there to boost my productivity a bit when debugging with ruby-debug or when working in the Rails console (where I use shorthand for everything I can!).

For the curious, making this gem was above all fun! But it was also a little bit weird... (at first I started going down the path of using a generator to create a base for my new gem, but that ended up being too clunky for me!) After all, I think github has done a pretty good job of making gem builds simple as basically all you've got to do is figure out how to add a <project_name>.gemspec file to your repo (as well as a Manifest and a CHANGELOG I found out). The best resource on that process that I found (better than the generators I tried) was, as usual, the one proposed by Ryan Bates in his Making a Gem railscast. And then of course the GitHub RubyGems guide was also very concise and helpful when things weren't quite working properly. Also, one thing that neither of these resources ever mentioned is that github even sends you a status email indicating whether or not the build on your gem passed or failed and why. Pretty cool!

No comments:

Post a Comment