Module: Mongoid::Extensions::Date::ClassMethods

Defined in:
lib/mongoid/extensions/date.rb

Instance Method Summary collapse

Instance Method Details

#demongoize(object) ⇒ Date

Convert the object from it’s mongo friendly ruby type to this type.

Examples:

Demongoize the object.

Date.demongoize(object)

Parameters:

  • object (Time)

    The time from Mongo.

Returns:

  • (Date)

    The object as a date.

Since:

  • 3.0.0



43
44
45
# File 'lib/mongoid/extensions/date.rb', line 43

def demongoize(object)
  ::Date.new(object.year, object.month, object.day) if object
end

#mongoize(object) ⇒ Time

Turn the object from the ruby type we deal with to a Mongo friendly type.

Examples:

Mongoize the object.

Date.mongoize("2012-1-1")

Parameters:

  • object (Object)

    The object to mongoize.

Returns:

  • (Time)

    The object mongoized.

Since:

  • 3.0.0



58
59
60
61
62
63
# File 'lib/mongoid/extensions/date.rb', line 58

def mongoize(object)
  unless object.blank?
    time = object.__mongoize_time__
    ::Time.utc(time.year, time.month, time.day)
  end
end