class Money
Class name does not really matches the folder hierarchy, because in order for (de)serialization to work, the class must be re-opened. But this file brings mongoid 2.X compat., so…
Public Class Methods
demongoize(object)
click to toggle source
Get the object as it was stored in the database, and instantiate this custom class from it.
# File lib/money-rails/mongoid/three.rb, line 15 def demongoize(object) return nil if object.nil? object.symbolize_keys! ::Money.new(object[:cents], object[:currency_iso]) end
evolve(object)
click to toggle source
Converts the object that was supplied to a criteria and converts it into a database friendly form.
# File lib/money-rails/mongoid/three.rb, line 35 def evolve(object) case object when Money then object.mongoize else object end end
mongoize(object)
click to toggle source
Takes any possible object and converts it to how it would be stored in the database.
# File lib/money-rails/mongoid/three.rb, line 23 def mongoize(object) case object when Money then object.mongoize when Hash then object.symbolize_keys! ::Money.new(object[:cents], object[:currency]).mongoize else object end end
Public Instance Methods
deserialize(object)
click to toggle source
Mongo friendly -> Money
# File lib/money-rails/mongoid/two.rb, line 9 def deserialize(object) return nil if object.nil? object = object.with_indifferent_access ::Money.new object[:cents], object[:currency_iso] end
mongoize()
click to toggle source
Converts an object of this instance into a database friendly value.
# File lib/money-rails/mongoid/three.rb, line 4 def mongoize { :cents => cents, :currency_iso => currency.iso_code } end
serialize(object)
click to toggle source
Money
-> Mongo friendly
# File lib/money-rails/mongoid/two.rb, line 17 def serialize(object) return nil unless object.is_a? Money { :cents => object.cents, :currency_iso => object.currency.iso_code } end