lib/money-rails/mongoid/money.rb in money-rails-1.2.0 vs lib/money-rails/mongoid/money.rb in money-rails-1.3.0

- old
+ new

@@ -12,11 +12,15 @@ # Get the object as it was stored in the database, and instantiate # this custom class from it. def demongoize(object) if object.is_a?(Hash) - object = object.deep_symbolize_keys + if object.respond_to?(:deep_symbolize_keys) + object = object.deep_symbolize_keys + else + object = object.symbolize_keys + end object.has_key?(:cents) ? ::Money.new(object[:cents], object[:currency_iso]) : nil else nil end end @@ -25,10 +29,14 @@ # stored in the database. def mongoize(object) case when object.is_a?(Money) then object.mongoize when object.is_a?(Hash) then - object.deep_symbolize_keys! if object.respond_to?(:deep_symbolize_keys!) + if object.respond_to?(:deep_symbolize_keys!) + object.deep_symbolize_keys! + elsif object.respond_to?(:symbolize_keys!) + object.symbolize_keys! + end ::Money.new(object[:cents], object[:currency_iso]).mongoize when object.respond_to?(:to_money) then begin object.to_money.mongoize rescue ArgumentError, Money::Currency::UnknownCurrency