Class: Mongoid::Fields::Internal::Array

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

Overview

Defines the behaviour for array fields.

Instance Attribute Summary

Attributes included from Serializable

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

Instance Method Summary collapse

Methods included from Serializable

#constraint, #deserialize, #eval_default, #foreign_key?, #localized?, #metadata, #object_id_field?, #selection, #type, #versioned?

Instance Method Details

#add_atomic_changes(document, name, key, mods, new, old) ⇒ Object

Adds the atomic changes for this type of resizable field.

Examples:

Add the atomic changes.

field.add_atomic_changes(doc, "key", {}, [], [])

Parameters:

  • document (Document)

    The document to add to.

  • name (String)

    The name of the field.

  • key (String)

    The atomic location of the field.

  • mods (Hash)

    The current modifications.

  • new (Array)

    The new elements to add.

  • old (Array)

    The old elements getting removed.

Since:

  • 2.4.0



23
24
25
# File 'lib/mongoid/fields/internal/array.rb', line 23

def add_atomic_changes(document, name, key, mods, new, old)
  mods[key] = new
end

#resizable?true

Array fields are resizable.

Examples:

Is this field resizable?

field.resizable?

Returns:

  • (true)

    Always true.

Since:

  • 2.4.0



35
# File 'lib/mongoid/fields/internal/array.rb', line 35

def resizable?; true; 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 object.

Since:

  • 2.1.0



48
49
50
# File 'lib/mongoid/fields/internal/array.rb', line 48

def serialize(object)
  raise_or_return(object)
end