Miscellaneous Archives

Getting Started With DataMapper and Rails

Posted on September 17th, 2007 by Chris

I’ve been tracking progress on the DataMapper ORM framework for a little while now and was pleased to see it moved recently to a shiny new site. To celebrate the progress, I decided to write a little bit about how to get started using DataMapper in a Rails application.

The DataMapper ORM derives its name from a Martin Fowler pattern, much like its data access brethren ActiveRecord. Very simplistically, the two patterns differ primarily in regards to how much they are ORM aware, the Mapper pattern in this case ends up trading some magic for greater flexibility. Hibernate is perhaps the preeminent (or at least most popular) open source DataMapper ORM at the moment, and its very well documented in numerous books if you feel like exploring the pattern in greater depth.

With that, lets explore setting up a simple Rails application using DataMapper. To begin with, download the DataMapper gem:


    sudo gem install datamapper
 

As a firm believer in “vendor everything”, I’m using Dr. Nic’s Gems on Rails gem to store my gems in my Rails vendor project folder. Using gems on rails (or anything similiar) is not a prerequisite to using DataMapper, but I find it makes it easier to make code tweaks (not to mention keep others you’re working with more sane in CI enviroments). If you do find yourself using the gem, you’ll need to change the following line in the datamapper init.rb file: require_options = ["datamapper"] to be ["data_mapper"].

After making those changes, go ahead and set up your database.yml file and create your database. DataMapper is able to use your database.yml. However, I had to comment out the following line in data_mapper.rb to get that working: cache WeakHash::Factory. Not exactly sure why yet, but perhaps I’ll get to that later.

Anyway, after that you need to require the following at the bottom of your environment.rb:


require 'rubygems'
require 'data_mapper'

I also turned off active_record as I’m running edge rails:


config.frameworks -= [ :action_web_service, :action_mailer, :active_record ]

Next, go ahead and define your models. In my case, I was building a restaurant application with a cocktail menu. So I created a Drink model:


class Drink < DataMapper::Base
   property :name, :string
   belongs_to :menu
end

After I created my model, I wanted to test it right away to see where I was at. So I fired up the Rails console. DataMapper has a nice feature that allows one to create a table through an ORM API, in this case via the following command:


>> database.save(Drink)
=> true
>> Drink.superclass
=> DataMapper::Base

So far so good, so I decided to make myself a drink:


>> d = Drink.new
=> #
>> d.name = “Nice Cold Beer”
=> “Nice Cold Beer”
>> d.save
=> 1
>> Drink.find :all
=> [#]

A simple example, but also a harbinger of things to come. The code base is seeing quite a bit of activity from the 0.1.1 version I’m on and I look forward to exploring more, particularly around advanced associations and performance. Cheers.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Capistrano SSHAgent Error

Posted on September 8th, 2007 by Chris

Small Capistrano tidbit. If you see the following error when running cap deploy (or setup for that matter):
(Errno::ENOENT: No such file or directory - /tmp/501/SSHKeychain.socket), try using the following command: unset SSH_AUTH_SOCK. I think Capistrano may just be picking up an SSH_AUTH_SOCK environment variable set by some prior ssh-agent that is potentially no longer there. Thats how it appears, at least. BTW, I’m running Capistrano 2.0 from a mac.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Mimicry is the highest form of flattery

Posted on August 23rd, 2007 by Jeff

Below are two screen shots. One is of the Bust Out Solutions website circa January 2007 when we were undergoing a website re-alignment to bring it to the state in which you see it now. The next screen shot is of advanceddigitalstudios.com (circa August 2007), a domain owned by Robert Clark for a company in East Hartford, Connecticut. I have never met Robert nor do I know anything about his company, but through the power of integrated website analytics I found this ripoff. Let’s wait to see what the site looks like when it launches.

bustoutsolutions.com (January 2007)

The temporary Bust Out Solutions website

advanceddigitalstudios.com (August 2007)

Advanced Digital Studios

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Hello, iPhone. How are you?

Posted on June 29th, 2007 by Jeff

Yes, I use Apple products. No, I am not a groupie. Well, not totally.

I have been using Apple products since the 8th grade, when they were cool but before they were really cool. So I guess in some ways Apple hooked me young and is now just reeling it in. I’m not one of those die-hard, religious fanatics that won’t touch a PC for moral reasons. In general, I’m a pragmatist, using the appropriate tools to solve the problem at hand, and finding out what makes me the most productive. With computers, this happens to be Apple products 90% of the time.

Apple’s new iPhone

For other products, such as cell phones, it’s my junky Nokia that makes great phone calls and wakes me up in the morning. The iPhone looks awesome, but it’s not really something I’m interested in at this time, only because I’m not a big fan of bells and whistles on anything, be it a cell phone, camera, or a website. Again, I’m not totally against cool features, as long as they make sense. For a lot of people the iPhone is their holy grail of PDAs, so they really should run to the nearest Apple store, fight the crowds and buy one of those suckers NOW. I’ll wait until I find a need for one, then get one after the bugs are worked out and the newer versions are released.

At any rate, congratulations to Apple for pushing the envelope yet again.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

On Simplicity

Posted on May 29th, 2007 by Chris

Two interesting recent articles on the virtues of keeping things (products, projects, etc) small and simple. Be humble, think about your users, create great projects and better code.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

MacBook Pro fan failure

Posted on April 22nd, 2007 by Jeff

I came across a blog entry just slamming Apple hardware for being faulty, and immediately wrote it off as a pissed off, overly-opinionated rant that had no grounds in reality. Then about two hours later, my MacBook Pro began making a noise like a race car engine. When a laptop sounds like it’s about to burn rubber and tear off around the corner, you know something is seriously wrong. I was exactly one month out of warranty and my laptop’s cooling fans just died. Mild distress set in which eventually turned to disappointment, then just plain anger. I decided to take apart my machine to try and fix it myself, which led to three good lessons:

  1. smcFanControl is a great application that lets you manually control the fan speed of you Macintosh computer, allowing you to manage heat.
  2. Ifixit has a fantastic guide on how to take apart your MacBook Pro and install new parts. Use it.
  3. If you can’t get the casing off your laptop at 3:00 in the morning after having 4 beers, shut your machine down, take it to the Apple store the next day, and they will fix it for free even if you are outside the warranty period.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]

Hello world!

Posted on March 9th, 2007 by Jeff

Welcome to the new Bust Out Solutions, Inc. website! The structure of this site is based on the elastic layout, which means almost everything is defined relative to the size of the text. Nothing is defined in pixels, the traditional method for determining widths and heights on a computer screen. A pixel is a fixed size, whereas the “em” is a unit of size based on the size of the font. This method increases the accessibility of the site since many users with poor vision choose to set a larger default font size in the browser. Give it a whirl, click around the site, and let me know what you think!

Special thanks to Andrew Bessler of Play for his graphic design help on the site.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]