19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/acts_as_money.rb', line 19
def money(name, options = {})
mapping = [[(options[:cents] || :cents).to_s, 'cents']]
mapping << [(options[:currency] || :currency).to_s, 'currency_as_string'] if options[:currency] != false
composed_of name, {
:class_name => 'Money',
:allow_nil => options[:allow_nil],
:mapping => mapping,
:constructor => Proc.new { |cents, currency| options[:allow_nil] && !cents ? nil : Money.new(cents || 0, currency || Money.default_currency) },
:converter => Proc.new { |value|
ret = value
begin
ret = value.to_money
rescue
end
ret
}
}
end
|