Standup 12/21/2009: Bundler and symbol.to_proc

Ask for Help

“How do I make attachment_fu use both the file system and S3 as storage backends?”

One of our clients would like to migrate attachments from the file system to S3. They want a clever way to make attachment_fu look in S3 or the filesystem, where new files are in S3 and old files are in the filesystem.

Their current solution, which they’re not super happy with, is to monkeypatch the S3 backend by extending it with file system methods. This solution doesn’t really seem to work too well, since the two backends share some of the same methods, and calling “extend FileSystemBackend” doesn’t give them the freedom to pick and choose their methods. In addition, their patch makes the S3 backend not be an S3 backend any more, which could cause problems for maintenance down the road.

A better solution is to define a new backend object, based on the S3 backend but falling back to file system-style methods. Attachment_fu supports defining custom backend modules; a class using :storage => :my_storage would look for a backend module called Technoweenie::AttachmentFu::Backends::MyStorageBackend.

Attachment_fu still has a design problem. The backend objects are all modules, not classes. As a result, it’s not easy to make a new backend descend from one of the existing backends.

Interesting Things

The new version of the bundler gem, version 0.7.2, does not seem to be Ruby 1.8.6 compliant. The gem relies on symbol.to_proc, which is part of Ruby 1.8.7 (and Rails). A native Ruby 1.8.6 without Rails does not support this method.

2 Comments

Is it not easiest to upload all files in one go, and after that use the S3 backend exclusively?

Can they not do that?

Stephan

December 21, 2009 at 1:21 pm

AW says:

I had that very same thought… upload existing assets to Amazon S3 in bulk.

If you’ve got a system that can’t go down for the hour or so it’d take, modify production to save locally and to Amazon S3 simultaneously… then once the bulk upload is done, switch over to Amazon S3 exclusively, and bin the local filesystem uploads.