Module: Mongoid::Extensions::BigDecimal::ClassMethods

Defined in:
lib/mongoid/extensions/big_decimal.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) demongoize(object)

Convert the object from its mongo friendly ruby type to this type.

Examples:

Demongoize the object.

Object.demongoize(object)

Since:

  • 3.0.0



43
44
45
46
47
# File 'lib/mongoid/extensions/big_decimal.rb', line 43

def demongoize(object)
  if object
    object.numeric? ? ::BigDecimal.new(object.to_s) : object
  end
end

- (String) mongoize(object)

Mongoize an object of any type to how it's stored in the db as a big decimal.

Examples:

Mongoize the object.

BigDecimal.mongoize(123)

Since:

  • 3.0.7



60
61
62
# File 'lib/mongoid/extensions/big_decimal.rb', line 60

def mongoize(object)
  object ? object.to_s : object
end