Class: Mongoid::Fields::Internal::Set

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

Overview

Defines the behaviour for set 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) ⇒ Set

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:

  • (Set)

    The converted set.

Since:

  • 2.1.0



21
22
23
# File 'lib/mongoid/fields/internal/set.rb', line 21

def deserialize(object)
  ::Set.new(object)
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



35
36
37
38
# File 'lib/mongoid/fields/internal/set.rb', line 35

def selection(object)
  return object unless object.is_a?(::Set)
  serialize(object)
end

#serialize(object) ⇒ Array

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:

  • (Array)

    The converted array.

Since:

  • 2.1.0



51
52
53
# File 'lib/mongoid/fields/internal/set.rb', line 51

def serialize(object)
  object.to_a
end