genki (owner)

Revisions

gist: 98573 Download_button fork
public
Public Clone URL: git://gist.github.com/98573.git
Embed All Files: show embed
currency.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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