Class: ActiveRecord::Type::Spanner::Time

Inherits:
Time
  • Object
show all
Defined in:
lib/active_record/type/spanner/time.rb

Instance Method Summary collapse

Instance Method Details

#serialize(value) ⇒ Object



22
23
24
25
# File 'lib/active_record/type/spanner/time.rb', line 22

def serialize value
  val = super value
  val.acts_like?(:time) ? val.utc.rfc3339(9) : val
end

#serialize_with_isolation_level(value, isolation_level) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/active_record/type/spanner/time.rb', line 13

def serialize_with_isolation_level value, isolation_level
  if value == :commit_timestamp
    return "PENDING_COMMIT_TIMESTAMP()" if isolation_level == :dml
    return "spanner.commit_timestamp()" if isolation_level == :mutation
  end

  serialize value
end

#user_input_in_time_zone(value) ⇒ Object



27
28
29
30
# File 'lib/active_record/type/spanner/time.rb', line 27

def user_input_in_time_zone value
  return value.in_time_zone if value.is_a? ::Time
  super value
end