I’m writing an application which has store locator-like use cases. If you’ve ever written anything like this, you know that the SQL can get quite messy. To keep my code clean and elegant, I’ve written a Rails plugin called acts_as_mappable to ease my development. Perhaps it will help others as well.
With this being my first Rails plugin, some disclaimers are in order. First, its very v0.1 and experimental. While its written to potentially support multiple databases, it not only supports MySQL. Also, as primarily a Java developer, I find it sometimes challenging to write idiomatic Ruby. If you review the source for the plugin, you may recognize opportunities for improvement. If you’d like to make some suggestions, I’m very open to receiving them. Also, any patches or bug reports would be appreciated too.
The README file contains a pretty complete guide to the plugins capabilities — it basically provides distance calculation and query services. The test suite is also fairly extensive, so you can review it to get a good idea of what you can do. In typical Rails fashion, mixing this in would like something like this:
1
2
3
4
5
6
|
class Location < ActiveRecord::Base
belongs_to :company
# Pretty SQL distance queries and distance calculations.
acts_as_mappable
end
|
And then there’s a host of finders that become available. If this whets your appetite, give it a look.
At present, the plugin is available here, but I’ll make it available in a public SVN repository sometime soon.