Oh no you didn’t…?! December 20
My blog (i.e., this blog) suddenly stopped working today, so I went to the logs to figure out why. The logs provided:
ActionView::TemplateError (undefined method `first' for nil:NilClass) on line #9
of vendor/plugins/flickr_sidebar/views/content.rhtml:
[... lots and lots of stuff ...] Ah, OK. I haven't gotten Typo current since I decided to roll my own (which I'm still doing...), so it serves me right if some bug is biting me. Off to look at the Flickr sidebar, and this chestnut is what's choking things:
def image
description.scan( /(http:\/\/(static|photos).*?\.jpg)/ ).first.first
end Gah! Using a regular expression to capture a link to an image out of escaped HTML markup passed in the RSS feed... Not something I would recommend. Flickr changed their URLs so that the regular expression no longer matched, and the error was caused by scan returning nil. It's easy enough to fix by adding some namespaces:
@@NS = {"media" => "http://search.yahoo.com/mrss/" } And then, a couple of tweaks to extract the thumbnail from the appropriate extension element:
picture.thumbnail = XPath.match(elem, "media:thumbnail/@url",
namespaces=@@NS).to_s And we're back in business.
Annc: The Ruby Underground December 15
Following on the heels of my last post, I’d like to announce the Ruby Underground. It’s simply a selective aggregator of Ruby blogger content. There’s already plenty of sources for generic ruby content. Tons of 20-something youngsters (yes, I’m old) are out there talking about Ruby on Rails and such.
The Ruby Underground tries to address a slightly different audience. Thus far, all contributors to the underground are either current or former Java hackers. They’ve been around the block a time or two and feel squeamish watching all the SQL that ActiveRecord throws. Yet, they have an affinity to the beauty of Ruby.
While “enterprisey” is typically a derisive term, I think the Ruby community could use some “enterpriseyness” to help bring it, um, to the enterprise.
Anyhow, the Ruby Underground, as noted, is just an aggregator. If you already read Bob, Brian, Dion, Kurt, Lance, Martin, Paul and Simon, it probably has nothing to offer you. On the other hand, you’ll miss out when other bloggers are invited to be contributors.
Duck typing and business rules December 13
Rules engines have long had the concept of the "head" of a fact - this is basically some kind of a type indicator to tell the engine how to handle the fact.
Imagine we had 2 facts: Accident, and Driver - which represent elements of an insurance claim. It wouldn't make sense to apply the same tests and constraints to each and every fact. For instance, and Accident probably doesn't have an "age" attribute. In rule engine terms (going back a ways) you would represent these facts via a deftemplate, or an ordered fact. In either case, it is a structure that has a name: so the rule engine knows what path to send "accidents" down etc, for efficiency (and also what fields/slots are valid). In the OO world with objects, the equivalent is Class, or type. This is fine in statically typed languages like Java, a strong type is part of your everyday life for better or worse. However, in ruby typeis more rubbery: duck typing is so common no one even calls it duck typing ! A class is almost just a loose contract or construct of convenience more then anything else.
So how to handle this with rule engines? I see 3 options: 1) make people use classes to identify a type, 2) have each fact respond to a certain method to tell an interested part what its "rule type" or "template" is, or 3) use a construct for the rules similar to the olde deftemplate idea: where you define the fields up front that the rule will operate on. You then check facts to work out what template it is closest to.
I am leaning towards 3, by having a template concept, it is both simple, and makes it convenient for duck types. It has the added benefit of allowing the rules to be restricted to methods/accessors indicated in the template construct, rather then exposing the object naked. With some metaprogramming magic its quite easy to achieve too. The only down side is possibly that it may be ambiguous what template a fact conforms to, we will see...
And so it begins December 13
Just started checking in fragments that I have been scratching around on my laptop. Most of the engine is now functional (actually all) except for when I change my mind.
The YAML based parser I am still experimenting with ideas with (and trying to not tinker too much). Mucho thanks to the codehaus for setting this all up (Ben and Bob). Codehaus infrastructure makes life so much easier. I will keep all documentation in Confluence. I just need to work out how to turn on the "Web 2 point Oh" style for confluence wikis.
I am using www.easyeclipse.org as a development environment (see the LAMP distributions, and the RoR one in particular). I do find I am using IRB pretty extensively just to fumble my way around, I am hoping that as JRuby becomes complete then EasyEclipse may bundle it for better out-of-box experience (of course the many platform specific distros in Ruby are also more then adequate).
The project home page here here but the more useful page is the project "xircles" page here.
Watch this space. I am hoping to have a little spare time to get version 1 (do I have to call it BETA? ) out in a month or two.
Michael.
On Hiring December 12
I've been really feeling the pain of trying to hire a good developer lately.
We've been posting Craigslist ads, and we feel that we have all of the right keywords in place (Rails, Agile, Cheminformatics, Data Mining, Java, etc), and a bunch of cool challenging problems to work on, but we're not getting back much as far as quality responses go.
Maybe the job market really is that hot right now. Everyone I know seems to have multiple offers on their plate. Still, we're refusing to lower our standards, but we are starting to feel the drag of just not having enough people to get everything done. Anyone out there with any suggestions (or better yet, resumes of good people)? Email or comment if you've got them.
Conventions Were Made to be Broken December 1
The Rails convention for naming foreign key fields is to use the singular name of the table with a suffix of _id.
In the past few days a number of people using the Foreign Key Migrations plugin together with ActiveRecord session store have discovered that the exception to the rule is session_id in the sessions table. In this case, session_id is not a recursive relationship but an unfortunately named field.
The solution is to update the migration script and add :references => nil to the line that adds the session_id. The plugin will then ignore the column and not attempt to generate a database foreign key constraint.
RedHill on Rails Plugins 1.2 December 1
With the pending release of Rails 1.2, I've taken the opportunity to begin updating the plugins to take advantage of various 1.2 features such as alias_method_chain and to remove where possible, work-arounds for bugs that have been fixed. So, as of today, the trunk will only run against Rails 1.2.
For those not lucky or perhaps not foolish enough to start using the latest and greatest that Rails has to offer, you can find all the Rails 1.1.6 compatible versions of the plugins at:
svn://rubyforge.org/var/svn/redhillonrails/tags/release-1.1.6/vendor/plugins
Enjoy!
