Flagger 0.9.5 is out

Flagger got a little bug fix yesterday, in that it now recognises after_mark_as_* callbacks if they are private methods. This should really have been there in the beginning, I just left a couple of true arguments out somewhere. Get it like this:

script plugin intstall

http://svn.jcoglan.com/flagger/tags/0.9.5/flagger

Flagger now at 0.9.4, and a new JS library in the works

See, I knew I wasn’t cut out for blogging. I keep forgetting to post code updates, when that’s precisely the reason I set this thing up. Anyway. Flagger is now at version 0.9.4. Most of the changes are bug fixes. 0.9.4 closes a bug where the wrong callbacks got called in some situations. Since 0.9.1 there’s also been a functional change, in that after_mark_as_* methods are only called if their corresponding attribute is changed by a mark_as_* call.

In other news, I’m working on a JavaScript library. Not a Prototype/jQuery competitor, oh my no. I saw this the other day and decided I’d have a go at writing something similar, as an exercise in not completely forgetting how to do maths. I’ve noticed that much JavaScript that attempts to to anything geometrical does so by throwing piles of arrays around rather than having any real classes doing the work. That is to say, they favour things like

var c = vector_add([0,3,7], [5,2,8]);

whereas I’d rather write

var a = Vector.create([0,3,7]);
var b = Vector.create([5,2,8]);
var c = a.add(b);

Obviously, for this trivial example that’s a lot more work. The point of what I’m working on is that a and b are fully-fledged Vector objects with loads of useful methods attached to them for letting them interact with other vectors, matrices, lines, planes, etc. Also, a more object-oriented approach leads to better code legibility and lets you write code that’s closer to the maths it represents. As a quick sneak-preview, here’s the method for finding the intersection of two lines in 3D space:

this.intersectionWith = function(obj) {
  if (!this.intersects(obj)) { return null; }
  var P = this.anchor, X = this.direction,
      Q = obj.anchor, Y = obj.direction;
  var a = (X.dot(Q.subtract(P)) * Y.dot(Y) / X.dot(X)) +
      (X.dot(Y) * Y.dot(P.subtract(Q)));
  var s = a / (Y.dot(Y) - (X.dot(Y) * X.dot(Y)));
  return P.add(X.x(s));
};

I guarantee that would be a lot harder to follow if we were passing around lots of arrays and for loops. You might not understand what lines 5 and 6 do, but the point is that it reads almost exactly like the maths would on paper. More news on a release date soon (hopefully).

Flagger updated to 0.9.1

Flagger, my Rails plugin for handling boolean attributes in ActiveRecord, has been updated to version 0.9.1. This release fixes a problem whereby if an ActiveRecord model class defines constants with the same names as those used in Flagger, Flagger doesn’t work. Everything has been restructured to provide more sensible namespaces for the various bits, but functionally nothing has changed. See the project page for installation details.

This release also includes a patch for testing against the just-released Rails 1.2.3. Don’t say I don’t spoil you.

Flagger 0.9.0 released

I’ve just released a Rails plugin that simplifies dealing with boolean flags in ActiveRecord. It gives you a load of easy-to-read dynamic attribute-based finders and setter methods without you having to write a line of code. It’s perfect for eliminating the tedium that arises from defining things like this over and over again:

  class Order < ActiveRecord::Base
    def self.paid
      find_all_by_paid(true)
    end

    def self.unpaid
      find_all_by_paid(false)
    end

    def mark_as_paid
      update_attribute(:paid, true)
      # related tasks
    end

    def mark_as_unpaid
      update_attribute(:paid, false)
      # related tasks
    end
  end

There’s more information on the Flagger project page. Any feedback – comments, bugs, testing with obscure DBs – is very welcome.