Created
September 25, 2008 22:26
-
-
Save paul/12968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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