Class: Mongoid::Fields::Serializable::BigDecimal

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Fields::Serializable
Defined in:
lib/mongoid/fields/serializable/big_decimal.rb

Overview

Defines the behaviour for big decimal fields.

Instance Attribute Summary

Attributes included from Mongoid::Fields::Serializable

#default_val, #label, #localize, #name, #options

Instance Method Summary collapse

Methods included from Mongoid::Fields::Serializable

#constraint, #eval_default, #localized?, #metadata, #object_id_field?, #type, #versioned?

Instance Method Details

#deserialize(object) ⇒ BigDecimal

Deserialize this field from the type stored in MongoDB to the type defined on the model.

Examples:

Deserialize the field.

field.deserialize(object)

Parameters:

  • object (Object)

    The object to cast.

Returns:

Since:

  • 2.1.0



21
22
23
# File 'lib/mongoid/fields/serializable/big_decimal.rb', line 21

def deserialize(object)
  object ? ::BigDecimal.new(object) : object
end

#serialize(object) ⇒ String

Serialize the object from the type defined in the model to a MongoDB compatible object to store.

Examples:

Serialize the field.

field.serialize(object)

Parameters:

  • object (Object)

    The object to cast.

Returns:

  • (String)

    The converted string.

Since:

  • 2.1.0



36
37
38
# File 'lib/mongoid/fields/serializable/big_decimal.rb', line 36

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