Skip to content

Instantly share code, notes, and snippets.

@paul
Created September 25, 2008 22:26
Show Gist options
  • Save paul/12968 to your computer and use it in GitHub Desktop.
Save paul/12968 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'uuidtools'
module DataMapper
module Types
class UUID < DataMapper::Type
default lambda { ::UUID.random_create }
def self.load(value, property)
puts value.inspect
return nil if value.nil?
::UUID.parse(value)
end
def self.dump(value, property)
return nil if value.nil?
value.to_s
end
def self.typecast(value, property)
value.kind_of?(::UUID) ? value : load(value, property)
end
::DataMapper::Property::TYPES << self
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment