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

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

Instance Method Summary collapse

Instance Method Details

#demongoize(object) ⇒ Object

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

Examples:

Demongoize the object.

Object.demongoize(object)

Parameters:

  • object (Object)

    The object to demongoize.

Returns:

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

#mongoize(object) ⇒ String

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)

Parameters:

  • object (Object)

    The object to Mongoize

Returns:

  • (String)

    The mongoized object.

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