Class: Mongoid::Fields::Internal::Symbol
- Includes:
- Serializable
- Defined in:
- lib/mongoid/fields/internal/symbol.rb
Overview
Defines the behaviour for symbol fields.
Instance Attribute Summary
Attributes included from Serializable
#default_val, #label, #localize, #name, #options
Instance Method Summary collapse
-
#selection(object) ⇒ Object
Special case to serialize the object.
-
#serialize(object) ⇒ Symbol
(also: #deserialize)
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
#selection(object) ⇒ Object
Special case to serialize the object.
20 21 22 23 |
# File 'lib/mongoid/fields/internal/symbol.rb', line 20 def selection(object) return object if object.is_a?(::Hash) serialize(object) end |
#serialize(object) ⇒ Symbol Also known as: deserialize
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
36 37 38 |
# File 'lib/mongoid/fields/internal/symbol.rb', line 36 def serialize(object) object.blank? ? nil : object.to_sym end |