Class: DataMapper::Property::ParseDate

Inherits:
Object
  • Object
show all
Defined in:
lib/property/parse_date.rb

Instance Method Summary collapse

Instance Method Details

#dump(value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/property/parse_date.rb', line 6

def dump(value)
  case value
  when ::Date
    {"__type" => "Date", "iso" => value.to_datetime.utc.iso8601(3)}
  when ::DateTime
    {"__type" => "Date", "iso" => value.utc.iso8601(3)}
  when ::Hash
    value
  end
end

#load(value) ⇒ Object



17
18
19
# File 'lib/property/parse_date.rb', line 17

def load(value)
  typecast(value)
end

#typecast(value) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/property/parse_date.rb', line 21

def typecast(value)
  case value
  when ::Hash
    value["iso"].to_datetime
  when ::NilClass
    value
  else
    value.to_datetime
  end
end