Skip to content

Instantly share code, notes, and snippets.

@genki
Created April 20, 2009 15:05
Show Gist options
  • Save genki/98573 to your computer and use it in GitHub Desktop.
Save genki/98573 to your computer and use it in GitHub Desktop.
module DataMapper
module Types
class Currency < DataMapper::Type
class BigDecimal255 < ::BigDecimal
limit 255
end
primitive String
size 255
def self.load(value, property)
return nil if value.nil?
BigDecimal255.new(value.to_s)
end
def self.dump(value, property)
return nil if value.nil?
value.to_s
end
def self.typecast(value, property)
if value.kind_of?(BigDecimal255)
value
elsif value.nil?
load(nil, property)
else
load(value.to_s, property)
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment