module Sequel::Plugins::Timestamps::InstanceMethods
Public Instance Methods
before_update()
click to toggle source
Set the update timestamp when updating
Calls superclass method
# File lib/sequel/plugins/timestamps.rb, line 61 def before_update set_update_timestamp super end
Private Instance Methods
_before_validation()
click to toggle source
Set the create timestamp when creating
Calls superclass method
# File lib/sequel/plugins/timestamps.rb, line 69 def _before_validation set_create_timestamp if new? super end
set_create_timestamp(time=nil)
click to toggle source
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}=" 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?) set_update_timestamp(time) if model.set_update_timestamp_on_create? end
set_update_timestamp(time=nil)
click to toggle source
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}=" set_column_value(meth, time||model.dataset.current_datetime) if respond_to?(meth) end