Set the update timestamp when updating
# File lib/sequel/plugins/timestamps.rb, line 61 def before_update set_update_timestamp super end
Set the create timestamp when creating
# File lib/sequel/plugins/timestamps.rb, line 69 def _before_validation set_create_timestamp if new? super end
If the object has accessor methods for the create timestamp field, and the create timestamp value is nil or overwriting it is allowed, set the create timestamp field to the time given or the current time. If setting the update timestamp on creation is configured, set the update timestamp as well.
# File lib/sequel/plugins/timestamps.rb, line 79 def set_create_timestamp(time=nil) field = model.create_timestamp_field meth = :"#{field}=" self.send(meth, time||=model.dataset.current_datetime) if respond_to?(field) && respond_to?(meth) && (model.create_timestamp_overwrite? || send(field).nil?) set_update_timestamp(time) if model.set_update_timestamp_on_create? end
Set the update timestamp to the time given or the current time if the object has a setter method for the update timestamp field.
# File lib/sequel/plugins/timestamps.rb, line 88 def set_update_timestamp(time=nil) meth = :"#{model.update_timestamp_field}=" self.send(meth, time||model.dataset.current_datetime) if respond_to?(meth) end