Suggestions for adding a new abstract data type to AR using a composed_of

Hello everybody,

I had been searching the web but I can’t find a way to add a new abstract data type to AR using a composed_of. To put this in context let me explain what I want to do: In a rails app I had developed a Money Class that use to attr :amount, :currency. I had add functionality to have Factories for creating Money in different currencies, arithmetical operations, comparisons, and several financial calculations (interest, expected values, amortized payments, etc.) . I had been using this in my models as

composed_of :price_money,             :class_name => Money,             :mapping =>                 [ # database ruby                 [ :price, :amount ],                 [ :currency, :currency ]             ]

I have also a Bank Class were I kept the exchange rates among currencies After talking in RailsConf2008 with several railers they told me that will be good if I can deploy this as a plugin or a gem. I had been working in extracting this as a plugin, but I would like to be able to add a new abstract data type to AR for money, then we can use in migrations something like this as example:

  create_table "prices", :force => true do |t|     t.money "price", :precision => 16, :scale => 4. :default_currency => "USD"   end

Rather than

  create_table "prices", :force => true do |t|     t.decimal "price", :precision => 16, :scale => 4     t.string "currency", :limit => 3, :default => "USD", :null => false   end

And get out also the need for the composed_of declaration.

I will appreciate very much any suggestion how to tackle this.

Best regards,

Manuel Vidaurre