latimes / generates_uuid

An ActiveRecord mixin to wrap the functionality of uuidtools UUID generation for a model's attribute.

This URL has Read+Write access

reidmix (author)
Fri Nov 07 11:51:26 -0800 2008
commit  84950aa0e1f25f8e5cd75a30cfc48b7ffa88ec8e
tree    49d4f191a05b2ad2075c0ec662cfae2134126952
parent  217d8be498f175248a37d5714ae4f9133d13ce70
name age message
file MIT-LICENSE Loading commit data...
file README.rdoc
file init.rb
directory lib/
directory test/
README.rdoc

GeneratesUUID

An ActiveRecord mixin to wrap the functionality of uuidtools UUID generation for a model’s attribute (database column). By default, this uuid is stored in a column named uuid, to override this behavior, pass a symbol with the column name.

Requirement

Requires the uuidtools gem found on rubyforge at: rubyforge.org/projects/uuidtools/

Example

Specify:

  class User < ActiveRecord::Base
    generates_uuid
  end

Create:

  u = User.create!
  u.uuid => "0ce453f2-9d25-11dc-8e13-001b63955101"

Use a different column name:

  class Resource < ActiveRecord::Base
    generates_uuid :token
  end

  r = Resource.create!
  r.token => "7b151730-9cb7-11dc-bb8c-001b63955101"

Copyright © 2007 Los Angeles Times. All Rights Reserved.