Class: MongoModel::Types::Date

Inherits:
Object
  • Object
show all
Defined in:
lib/mongomodel/support/types/date.rb

Instance Method Summary collapse

Methods inherited from Object

#boolean, #to_query

Instance Method Details

#cast(value) ⇒ Object


7
8
9
10
11
12
13
14
15
16
# File 'lib/mongomodel/support/types/date.rb', line 7

def cast(value)
  case value
  when ::Array
    ::Date.new(*value)
  else
    value.to_date
  end
rescue
  nil
end

#from_mongo(value) ⇒ Object


22
23
24
# File 'lib/mongomodel/support/types/date.rb', line 22

def from_mongo(value)
  value.to_date if value
end

#to_mongo(value) ⇒ Object


18
19
20
# File 'lib/mongomodel/support/types/date.rb', line 18

def to_mongo(value)
  value.strftime("%Y/%m/%d") if value
end