Saturday, December 13, 2008

merb and sequel

Recently I needed to order some records by a mathematical formula, and I couldn't figure out a way to do it in DM (although it looks like the idea was well received and might make it into a future relase). I'd heard some great things about Sequel, so I decided to take a look and see what possibilities I had there.

If you haven't read anything about Sequel, head on over to its rubyforge page at http://sequel.rubyforge.org/documentation.html. There's a good amount of information from basics to how you can implement complex associations between models. There's even a link to Lori Holden's MerbCamp presentation.

Sequel piqued my interest in many ways: it uses the Active Record Pattern to create methods from column names, but you can also do a more DataMapper style definition of columns inside your model:



You can use Post.create_table! as a sort of automigrate (it will drop and recreate the table). The usage of set_schema is more for test code and experimenting, and I found it very useful when developing sequel_polymorphic and sequel_taggable.

So, while its easy enough to generate a new merb core app and customize it as you like, if you're going to be generating a lot of apps with the same configurations, its worth learning how to build a stack. Currently its mostly a manual process: you build a gem with a certain structure by hand, and then use your stack with merb-gen. Eventually this will probably be an easily streamlined process, but for now its still up to you to put things together. You can read more about the structure here and take a look at merb-sequel-stack as well.

If you're looking to get a bit closer to your DB and want a lot of flexibility and power, you should really take Sequel for a test drive. Its current maintainer, Jeremy Evans, has been a ton of help with answering dozens of questions in #sequel, even when its to answer something he doesn't agree with like polymorphic associations, which I'll go into next time.

Monday, December 1, 2008

a possible addition to www.builtbythenet.com

The same questions get answered many times a day in #merb and I have to think there's a better way, especially for dependency issues. Whether is a rubygems issue, one with Merb or any of the typical libraries people use it with, or just some random little bug you only see on windows, I haven't seen a good way to track and relate all of this information. Some goes on a wiki, some is remembered and routinely typed back by various people in #merb, some goes to the mailing list. It shouldn't have to be this way, and I'm hoping this idea will help:

dependency hell mitigator

The implementation would be dead simple, probably something like a tag cloud. It'd rely on people entering info and trying to keep things up to date...but hopefully this would result in a more organized and useful collection of all the various tricks we employ to get through those moments of keyboard tossing and mice bashing.

As usual anyone interested in coding this up is more than welcome to--the source is at jackdempsey/builtbythenet If enough people like this idea then I'll probably start in on it myself at some point and see where it goes.