Class: Mongoid::Fields::Serializable::Date

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Fields::Serializable, Timekeeping
Defined in:
lib/mongoid/fields/serializable/date.rb

Overview

Defines the behaviour for date fields.

Instance Attribute Summary

Attributes included from Mongoid::Fields::Serializable

#default_val, #label, #localize, #name, #options

Instance Method Summary collapse

Methods included from Timekeeping

#cast_on_read?, #serialize, #strip_milliseconds

Methods included from Mongoid::Fields::Serializable

#constraint, #eval_default, #localized?, #metadata, #object_id_field?, #serialize, #type, #versioned?

Instance Method Details

#deserialize(object) ⇒ Date

Deserialize this field from the type stored in MongoDB to the type defined on the model.

Examples:

Deserialize the field.

field.deserialize(object)

Parameters:

  • object (Object)

    The object to cast.

Returns:

  • (Date)

    The converted date.

Since:

  • 2.1.0



22
23
24
25
26
27
28
29
# File 'lib/mongoid/fields/serializable/date.rb', line 22

def deserialize(object)
 return nil if object.blank?
  if Mongoid::Config.use_utc?
    object.to_date
  else
    ::Date.new(object.year, object.month, object.day)
  end
end