Skip to content

Instantly share code, notes, and snippets.

@marcoow
Created October 16, 2009 13:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoow/211804 to your computer and use it in GitHub Desktop.
Save marcoow/211804 to your computer and use it in GitHub Desktop.
class ArbitraryModel < DataMapper::Type
primitive String
def self.dump(value, property)
"#{value.class}/#{value.id}" unless value.nil?
end
def self.load(value, property)
case value
when String
type, id = *value.split('/')
if (type = type.constantize) && type.is_a?(DataMapper::Model)
type.get(id)
else
raise ArgumentError.new('Only DataMapper models may be assigned!')
end
else
value
end
end
def self.typecast(value, property)
load(value, property)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment