module Sequel::Plugins::Timestamps::InstanceMethods
Public Instance Methods
Source
# File lib/sequel/plugins/timestamps.rb 74 def before_update 75 set_update_timestamp 76 super 77 end
Set the update timestamp when updating
Calls superclass method
Source
# File lib/sequel/plugins/timestamps.rb 80 def before_validation 81 set_create_timestamp if new? 82 super 83 end
Set the create timestamp when creating
Calls superclass method
Private Instance Methods
Source
# File lib/sequel/plugins/timestamps.rb 92 def set_create_timestamp(time=nil) 93 field = model.create_timestamp_field 94 meth = :"#{field}=" 95 set_column_value(meth, time||=model.dataset.current_datetime) if respond_to?(field) && respond_to?(meth) && (model.create_timestamp_overwrite? || get_column_value(field).nil?) 96 set_update_timestamp(time) if model.set_update_timestamp_on_create? 97 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.
Source
# File lib/sequel/plugins/timestamps.rb 101 def set_update_timestamp(time=nil) 102 return if model.allow_manual_timestamp_update? && modified?(model.update_timestamp_field) 103 meth = :"#{model.update_timestamp_field}=" 104 set_column_value(meth, time||model.dataset.current_datetime) if respond_to?(meth) 105 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.