Sha256: aae50bc8d66755623f56fdd1d6511cdb38ce5b654dff221d9f9335b1d97bcd92
Contents?: true
Size: 835 Bytes
Versions: 11
Compression:
Stored size: 835 Bytes
Contents
# encoding: utf-8 module Mongoid #:nodoc: module Fields #:nodoc: module Serializable #:nodoc: # Defines the behaviour for integer fields. class Integer include Serializable # 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 [ Integer ] The converted integer. # # @since 2.1.0 def serialize(object) return nil if object.blank? begin object.to_s =~ /\./ ? Float(object) : Integer(object) rescue object end end alias :set :serialize end end end end
Version data entries
11 entries across 11 versions & 1 rubygems