Class: Mongoid::Fields::Internal::BigDecimal
- Includes:
- Serializable
- Defined in:
- lib/mongoid/fields/internal/big_decimal.rb
Overview
Defines the behaviour for big decimal fields.
Instance Attribute Summary
Attributes included from Serializable
#default_val, #label, #localize, #name, #options
Instance Method Summary collapse
-
#deserialize(object) ⇒ BigDecimal
Deserialize this field from the type stored in MongoDB to the type defined on the model.
-
#selection(object) ⇒ Object
Special case to serialize the object.
-
#serialize(object) ⇒ String
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
Methods included from Serializable
#constraint, #eval_default, #foreign_key?, #localized?, #metadata, #object_id_field?, #resizable?, #type, #versioned?
Instance Method Details
#deserialize(object) ⇒ BigDecimal
Deserialize this field from the type stored in MongoDB to the type defined on the model.
21 22 23 24 25 26 27 28 29 |
# File 'lib/mongoid/fields/internal/big_decimal.rb', line 21 def deserialize(object) return object unless object begin Float(object) unless object == 'NaN' ::BigDecimal.new(object) rescue ArgumentError, TypeError object end end |
#selection(object) ⇒ Object
Special case to serialize the object.
41 42 43 44 |
# File 'lib/mongoid/fields/internal/big_decimal.rb', line 41 def selection(object) return object if object.is_a?(::Hash) serialize(object) end |
#serialize(object) ⇒ String
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
57 58 59 |
# File 'lib/mongoid/fields/internal/big_decimal.rb', line 57 def serialize(object) object ? object.to_s : object end |