Sha256: e3f411dbbe3923c6e9cd05471a240e09a979f78a5401b1b900da2e9eb35a9b01
Contents?: true
Size: 827 Bytes
Versions: 6
Compression:
Stored size: 827 Bytes
Contents
raise "ActiveRecord needs to be already required" unless defined?(ActiveRecord::Base) class ActiveRecord::Base # Convenience wrapper around ActiveRecord's composed_of method for Money attributes that need to be persisted. # # @param [Array of Symbols] # @example # composed_of_money :unit_price # composed_of_money :unit_price, :total_price def self.composed_of_money(*fields) fields.each do |field| composed_of field, :class_name => "Money", :mapping => [[field, "amount"]], :constructor => Proc.new { |amount| Money.new(amount || 0, Money.default_currency) }, :converter => Proc.new { |value| value.respond_to?(:to_money) ? value.to_money : raise(ArgumentError, "Can't convert #{value.class} to Money") } end end end
Version data entries
6 entries across 1 versions & 1 rubygems