Class: Mongoid::Fields::Internal::Integer
- Includes:
- Serializable
- Defined in:
- lib/mongoid/fields/internal/integer.rb
Overview
Defines the behaviour for integer 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) ⇒ Integer
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.
20 21 22 23 |
# File 'lib/mongoid/fields/internal/integer.rb', line 20 def selection(object) return object if object.is_a?(::Hash) serialize(object) end |
#serialize(object) ⇒ Integer
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
36 37 38 39 |
# File 'lib/mongoid/fields/internal/integer.rb', line 36 def serialize(object) return nil if object.blank? numeric(object) rescue object end |