I’ve come to really love working with Ruby on Rails – it forces a structured approach of Web development upon you which helps enough to get you organised, but doesn’t get in the way of being productive.
I’ve also learnt to search for plugins or gems whenever I need a specific functionality because more often than not somebody has already solved the problem that I am trying to address.
Today I played with Andy Singleton’s GUID plugin (global unique identifier) and found a bug. I haven’t found a way to publish the solution through the rails wiki (I’m really new to the community), so I’m posting it here. I’ve also sent Andy an email, so hopefully the issue will get addressed.
Here is what happend.
I got the plugin working on my development computer and wanted to test it on another machine. However, the plugin gave me the following error message:
#{RAILS_ROOT}/vendor/plugins/guid/lib/uuidtools.rb:235:in `timestamp_create'
#{RAILS_ROOT}/vendor/plugins/guid/lib/uuidtools.rb:225:in `timestamp_create'
#{RAILS_ROOT}/vendor/plugins/guid/lib/usesguid.rb:25:in `after_initialize'
After some digging I found that it uses the MAC address of the computer for seeding the GUID. To query the MAC address, it calls ifconfig (or ipconfig on a Windows machine) – which is fair enough. It has several cases that it goes through. However, the case of my machine was missing and the code did not address a nil return from the get_mac_address function.
My case was simple to solve: my MAC address comes in upper case characters, while the code only tested for lower-case characters. So, I added another parsing condition for my case:
if mac_addresses.size == 0
ifconfig_output = `/sbin/ifconfig | grep HWaddr | cut -c39-`
mac_addresses = ifconfig_output.scan(
Regexp.new("(#{(["[0-9A-F]{2}"] * 6).join(":")})"))
end
The generic problem is harder to solve – and maybe it should not be solved, but fail on the programmer, since he/she is trying to roll out GUID calculation on a machine where the program is unable to calculate a MAC address…..
Hmmm….