Adapting Ambitiously
It’s funny, really. All these people walking around, talking about Ambition. “Oh, Ambition? Yeah, pretty cool.” “Ambition? Impedance mismatch.” “I’m happy with SQL-92 the way it is, thank you very much.” Outrageous!
I know, I know. We’ve said some crazy things ourselves. Like how we wanted Ambition to be a Rack for databases. Or, far fetched as it sounds, how we hoped Ambition could evolve into something akin to LINQ. But we’re done talking.
Today we want to show you some plain jane Ruby and how Ambition empowers it to leverage its inherent synergy. Er, I mean, we want to show you something kickass.
New School
This is what we’re used to:
>> SQL::User.select { |m| m.name == 'jon' && m.age == 21 }.to_s => "SELECT * FROM users WHERE users.name = 'jon' AND users.age = 21"
This is what’s new:
>> LDAP::User.select { |m| m.name == 'jon' && m.age == 21 }.to_s => "(&(name=jon)(age=21))"
Adapter School
As of 0.5, Ambition is no longer a SQL wrapper. Rather, it is an API for writing your own adapters. If you’d like to continue using the ActiveRecord version of Ambition, please install the ambitious-activerecord gem:
$ gem install ambitious-activerecord
Then, of course, use it:
require 'rubygems' require 'ambition/adapters/active_record'
You can, too, install and use the older 0.3 series:
$ gem install ambition -v 0.3.2
Anyway, you heard right: Ambition now supports arbitrary data stores. Anything. Ambition adapters are just gems which depend on ambition and use its amazing API powers for the greater good.
What other adapters are underway? Oh, I dunno. How about ActiveLDAP, CouchDB, Facebook FQL, XPath, and DataMapper, to name a few. Why, just the other night the Boston.rb guys started working on a Sphinx adapter. Check it out with git:
$ git clone git://technicalpickles.com/ambitious_sphinx.git
We’ve also got two example gems: ambitious-activeldap and ambitious-activerecord.
There’s basic documentation for Ambition’s API over at ambition.rubyforge.org, which you are free to peruse as well.
We’re just starting out, but it’s not a bad start. Got an idea? Something crazy? We’re all about it. Jump on the mailing list or join #ambition on irc.freenode.net then chime in.
Dream School
Let’s take the youtube-g gem, as an example. There’s no finished adapter for it yet so we’re going to pretend.
Using the new Ambition, we could (behind the scenes) turn a query like this:
Videos.select { |video| video.user == 'liz' }
Into this:
YouTubeG::Client.new.videos_by(:user => 'liz')
We could turn a query like this:
Videos.select { |video| video.tags.include? 'apple' }
Into this:
YouTubeG::Client.new.videos_by(:tags => 'apple')
And we could even turn a query like this:
Videos.select do |video| video.tags.include?('football') && !video.tags.include?('soccer') end
Into this:
YouTubeG::Client.new.videos_by :tags => { :include => ['football'], :exclude => ['soccer'] }
Not bad. It even comes with a generator, courtesy of Dr Nic, for spitting out an adapter scaffold:
$ ambition_adapter ambitious_youtube
Future School
Got an idea for an adapter, or some code to show? Throw it in the comments. You better believe we’ll keep the rest of you abreast of cool adapters, fancy tricks, and new features.
Want to get involved? Like I said, there’s always the list and the GitHub repo. Bugs can go to Lighthouse and you can clone my repo thisaways:
$ git clone git://github.com/defunkt/ambition.git
Ah, how far we’ve come. And how far we’ll go! Here’s to it.


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago