class Terrestrial::Configurations::ConventionalConfiguration::TimestampObserver
Attributes
clock[R]
created_at_field[R]
created_at_setter[R]
dirty_map[R]
updated_at_field[R]
updated_at_setter[R]
Public Class Methods
new(clock, dirty_map, created_at_field, created_at_setter, updated_at_field, updated_at_setter)
click to toggle source
# File lib/terrestrial/configurations/conventional_configuration.rb, line 409 def initialize(clock, dirty_map, created_at_field, created_at_setter, updated_at_field, updated_at_setter) @clock = clock @dirty_map = dirty_map @created_at_field = created_at_field @created_at_setter = created_at_setter @updated_at_field = updated_at_field @updated_at_setter = updated_at_setter end
Public Instance Methods
post_save(mapping, object, record, new_record)
click to toggle source
# File lib/terrestrial/configurations/conventional_configuration.rb, line 433 def post_save(mapping, object, record, new_record) if created_at_field && record.fetch(created_at_field, false) time = record.fetch(created_at_field) created_at_setter.call(object, time) end if updated_at_field time = record.get(updated_at_field) updated_at_setter.call(object, time) end end
post_serialize(mapping, object, record)
click to toggle source
# File lib/terrestrial/configurations/conventional_configuration.rb, line 421 def post_serialize(mapping, object, record) time = clock.now if created_at_field && !record.get(created_at_field) record.set(created_at_field, time) end if updated_at_field && dirty_map.dirty?(record) record.set(updated_at_field, time) end end