Class: Mongoid::Fields::Internal::Set
- 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
-
#deserialize(object) ⇒ Set
Deserialize this field from the type stored in MongoDB to the type defined on the model.
-
#selection(object) ⇒ Object
Special case to serialize the object.
-
#serialize(object) ⇒ Array
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
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.
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.
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.
51 52 53 |
# File 'lib/mongoid/fields/internal/set.rb', line 51 def serialize(object) object.to_a end |