MetaWebLog API returns to Mephisto
July 22nd, 2008
At long last it looks like the MetaWebLog API has made it back into Mephisto as a plugin. I had started working on this myself but it was just too low priority for me with all the various things I have going on at the moment.
I know it was the intention of the Mephisto core team to stop this API from depending on the now deprecated ActionWebService framework and have someone else move it onto its own independent xmlrpc code. But to be honest this has been too long coming to turn down the plugin, even if it is still relying on ActionWebService (there seems to be a newish port of it on GitHub that might keep up with the rest of Rails with a new committing team).
And so onto the plugin itself, just drop by the RailsHacks blog to pickup the code and instructions for use. If you can see this post then it definitely works as I’ve just written it in the awesome MarsEdit and posted directly to this blog using it.
0 comments »Setting up Background Job (BJ) Properly
June 23rd, 2008
I dealt with a customer today who was a bit miffed that his Background Jobtasks were taking a while to kick off after the Rails app submitted them to the queue.
I dug a little deeper into the problem - he was using our standard configuration, moving control of the runner out to cron instead of being controlled from within the app itself.
1 |
Bj.config["production.no_tickle"] = true |
and then a cronjob such as
*/2 * * * * bj run --forever --rails_env=production --rails_root=/data/user/current
Extension-less Formats in ActiveResource
March 26th, 2008
When trying to integrate Litmus with Fetch recently we came across an API that whilst appearing RESTful, didn't quite map onto ActiveResource conventions because their URLs 404'd if we included .xml as the extension.
So I quickly whipped up a little plugin to let us specify new formats that don't include extensions.
1 2 3 4 5 6 7 |
class Something < ActiveResource::Base self.site = "http://someone:password@an-app.com" self.prefix = "/api/" self.format = :xml_no_extension end |
Now, calls to
Something.find(:all) |
Perfect!
You can grab the code from the ExtensionlessFormat GitHub repository
ActiveRecord Delegation and demeter
March 18th, 2007
A while ago I looked into the various aspects of the laws of demeter sparked by a post I read whilst trying to find out why Mephisto had the word “delegate” sprinkled throughout it.
If you haven’t come across demeter before then its worth reading the post I linked above and the Wikipedia Article
To sum up the concept in one short sentence, the magic that AR gives us that allow us to, for example, say: person.address.city is a dangerous thing to do. It’s all lovely and magic when its working but as soon as our person doesn’t have an address every reference to that throws a lovely nil.city error and promptly blows up our app.
Rails provides a delegate method which seems to have wrongly been assumed to handle this and protect delegated methods from returning nil errors but this isn’t the case. Using delegate you would expect to say:
delegate :city, :to => :address
and then expect to be able to call
person.city
without it all blowing up horribly if there is no address object attached to the person.
Well, after moaning about this to Dave we devised a new AR mixin called ar_delegate that lets you safely delegate methods to other classes and protect against the horrible nil errors that occur when you start nesting relationships using AR magic.
Dave has really come up with some lovely syntax that feels Railsey and hopefully we’ll be able to get this into core if it looks like its a good fit (and we write some tests). All credit to Dave for the code, I was merely an IM-advisor as he was writing it.
See ActiveRecord Delegation over at Dave’s blog for a much better write up and links to the plugin.

Feed me
