Class: Mongoid::Fields::Serializable::Range
- Includes:
- Mongoid::Fields::Serializable
- Defined in:
- lib/mongoid/fields/serializable/range.rb
Overview
Defines the behaviour for range fields.
Instance Attribute Summary
Attributes included from Mongoid::Fields::Serializable
#default_val, #label, #localize, #name, #options
Instance Method Summary collapse
-
#deserialize(object) ⇒ Range
Deserialize this field from the type stored in MongoDB to the type defined on the model.
-
#serialize(object) ⇒ Hash
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
Methods included from Mongoid::Fields::Serializable
#constraint, #eval_default, #localized?, #metadata, #object_id_field?, #type, #versioned?
Instance Method Details
#deserialize(object) ⇒ Range
Deserialize this field from the type stored in MongoDB to the type defined on the model.
21 22 23 |
# File 'lib/mongoid/fields/serializable/range.rb', line 21 def deserialize(object) object.nil? ? nil : ::Range.new(object["min"], object["max"]) end |
#serialize(object) ⇒ Hash
Serialize the object from the type defined in the model to a MongoDB compatible object to store.
36 37 38 |
# File 'lib/mongoid/fields/serializable/range.rb', line 36 def serialize(object) object.nil? ? nil : { "min" => object.min, "max" => object.max } end |