From: Tim Bates Date: 2003-09-11T09:15:29+09:00 Subject: Re: ANN: Criteria 1.0 On Mon, Sep 08, 2003 at 04:28:53PM +0900, Ryan Pavlik wrote: > Criteria 1.0 > ============ > > Criteria is a module for abstracting queries to various data sets. > For instance, you might have a flat text file, or an array of Ruby > objects, or a SQL database, and wish to perform the same query on > any given source, without different versions of code for each. > You can find Criteria at the following location: > > http://mephle.org/Criteria/ From the above address: Basics ------ To use the Critera module, it's helpful to understand how it works. The Table superclass is a class with most of the default instance methods removed. Instead, when given a method (including any operator methods), it generates a Criterion object in #method_missing. A Criterion is similar to a Table---it's another nearly-blank class, except it tracks the method call given to Table. It also chains to another Criterion. When evaluated recursively along this chain, the syntax of the statement can be restored. When I first saw the previous email, I thought - how on earth can he do that? It's a way to abstract queries to any sort of interface - something I've been trying to do for ages - and from the output it looks like it's somehow capturing the Ruby code and parsing it, but no; it's so much simpler than that. And done in only 65 lines of Ruby code. That is some seriously, seriously funky magic. Ryan, I'm extremely impressed. Once more the power of Ruby astounds me. The ability to translate the same abstract Ruby query into SQL code or an array lookup is just fantastic. Good work. One of these days I'm going to have to take a look at Mephle. If it's anything like as good as this, I'm in! Tim Bates -- tim@bates.id.au