Class: Mongoid::Fields::Internal::NilClass

Inherits:
Object
  • Object
show all
Includes:
Serializable
Defined in:
lib/mongoid/fields/internal/nil_class.rb

Overview

Defines the behaviour for nil fields.

Instance Attribute Summary

Attributes included from Serializable

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

Instance Method Summary collapse

Methods included from Serializable

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

Instance Method Details

#deserialize(object) ⇒ nil

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:

  • (nil)

    Always nil.

Since:

  • 2.1.0



21
# File 'lib/mongoid/fields/internal/nil_class.rb', line 21

def deserialize(object); nil; end

#selection(object) ⇒ Object

Special case to serialize the object.

Examples:

Convert to a selection.

field.selection(object)

Parameters:

  • The (Object)

    object to convert.

Returns:

  • (Object)

    The converted object.

Since:

  • 2.4.0



33
34
35
36
# File 'lib/mongoid/fields/internal/nil_class.rb', line 33

def selection(object)
  return object if object.is_a?(::Hash)
  serialize(object)
end

#serialize(object) ⇒ nil

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:

  • (nil)

    always nil.

Since:

  • 2.1.0



49
# File 'lib/mongoid/fields/internal/nil_class.rb', line 49

def serialize(object); nil; end