Class: DataMapper::Property::EpochTime

Inherits:
Integer
  • Object
show all
Defined in:
lib/dm-types/epoch_time.rb

Instance Method Summary collapse

Instance Method Details

#custom?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/dm-types/epoch_time.rb', line 19

def custom?
  true
end

#dump(value) ⇒ Object



15
16
17
# File 'lib/dm-types/epoch_time.rb', line 15

def dump(value)
  value.to_i if value
end

#load(value) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/dm-types/epoch_time.rb', line 7

def load(value)
  if value.kind_of?(::Numeric)
    ::Time.at(value.to_i)
  else
    value
  end
end

#typecast(value) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/dm-types/epoch_time.rb', line 23

def typecast(value)
  case value
    when ::Time               then value
    when ::Numeric, /\A\d+\z/ then ::Time.at(value.to_i)
    when ::DateTime           then datetime_to_time(value)
    when ::String             then ::Time.parse(value)
  end
end