Class: ActiveRecord::Embedded::Field::Time

Inherits:
ActiveRecord::Embedded::Field show all
Defined in:
lib/active_record/embedded/field/time.rb

Overview

Store timestamps in the database converted to UNIX Epoch Time, and casted as a Time object in Ruby.

Constant Summary

Constants inherited from ActiveRecord::Embedded::Field

PREFIX

Instance Attribute Summary

Attributes inherited from ActiveRecord::Embedded::Field

#default, #name

Instance Method Summary collapse

Methods inherited from ActiveRecord::Embedded::Field

#default?, #default_method_name, find, #initialize, types

Constructor Details

This class inherits a constructor from ActiveRecord::Embedded::Field

Instance Method Details

#cast(value) ⇒ Object

Convert a Time object to a numerical timestamp for persistence.


10
11
12
# File 'lib/active_record/embedded/field/time.rb', line 10

def cast(value)
  value.to_i
end

#coerce(value) ⇒ Object

Construct a Time object from a numerical timestamp for rendering.


16
17
18
# File 'lib/active_record/embedded/field/time.rb', line 16

def coerce(value)
  ::Time.at(value)
end