Class: Mongoid::Fields::Internal::Boolean
- Includes:
- Serializable
- Defined in:
- lib/mongoid/fields/internal/boolean.rb
Overview
Defines the behaviour for boolean fields.
Direct Known Subclasses
Constant Summary collapse
- MAPPINGS =
{ true => true, "true" => true, "TRUE" => true, "1" => true, 1 => true, 1.0 => true, false => false, "false" => false, "FALSE" => false, "0" => false, 0 => false, 0.0 => false }
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) ⇒ true, false
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
Methods included from Serializable
#constraint, #deserialize, #eval_default, #foreign_key?, #localized?, #metadata, #object_id_field?, #resizable?, #type, #versioned?
Instance Method Details
#selection(object) ⇒ Object
Special case to serialize the object.
35 36 37 38 |
# File 'lib/mongoid/fields/internal/boolean.rb', line 35 def selection(object) return object if object.is_a?(::Hash) serialize(object) end |
#serialize(object) ⇒ true, false
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
51 52 53 54 |
# File 'lib/mongoid/fields/internal/boolean.rb', line 51 def serialize(object) object = MAPPINGS[object] object.nil? ? nil : object end |