Sha256: 23320d842690824f878a129d5b08217a4ef1a1932b17aa8ff0210a454a5d6e48

Contents?: true

Size: 806 Bytes

Versions: 11

Compression:

Stored size: 806 Bytes

Contents

# encoding: utf-8
module Mongoid #:nodoc:
  module Fields #:nodoc:
    module Serializable #:nodoc:

      # Defines the behaviour for float fields.
      class Float
        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 [ Float ] The converted float.
        #
        # @since 2.1.0
        def serialize(object)
          return nil if object.blank?
          begin
            Float(object)
          rescue ArgumentError => e
            object
          end
        end
        alias :set :serialize
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
mongoid-2.2.0 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.9 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.8 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.7 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.6 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.5 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.4 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.3 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.2 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.1 lib/mongoid/fields/serializable/float.rb
mongoid-2.1.0 lib/mongoid/fields/serializable/float.rb