Sha256: a2b5507b5bd3fcc7d553edbe351d2c13dba071d1e30f65ae8618080e0a520573
Contents?: true
Size: 1.52 KB
Versions: 60
Compression:
Stored size: 1.52 KB
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Fields #:nodoc: module Internal #:nodoc: # Defines the behaviour for big decimal fields. class BigDecimal include Serializable # Deserialize this field from the type stored in MongoDB to the type # defined on the model. # # @example Deserialize the field. # field.deserialize(object) # # @param [ Object ] object The object to cast. # # @return [ BigDecimal ] The converted big decimal. # # @since 2.1.0 def deserialize(object) object ? ::BigDecimal.new(object) : object end # Special case to serialize the object. # # @example Convert to a selection. # field.selection(object) # # @param [ Object ] The object to convert. # # @return [ Object ] The converted object. # # @since 2.4.0 def selection(object) return object if object.is_a?(::Hash) serialize(object) end # Serialize the object from the type defined in the model to a MongoDB # compatible object to store. # # @example Serialize the field. # field.serialize(object) # # @param [ Object ] object The object to cast. # # @return [ String ] The converted string. # # @since 2.1.0 def serialize(object) object ? object.to_s : object end end end end end
Version data entries
60 entries across 60 versions & 3 rubygems